File size: 1,136 Bytes
f7e6f7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<#
    launch.ps1 - Launch TinyNotepad (MyNotepad.exe)

    Starts the GUI desktop application and writes ONLY its numeric PID to stdout
    as the first line. This script is standalone and does not depend on build.ps1
    having been run in the same session, but the application must already be
    built into the install directory.

    TinyNotepad is a plain .NET Framework WinForms app - no sandbox flags or
    user-data-dir needed.
#>

$ErrorActionPreference = 'Stop'

$InstallDir = (Join-Path (Split-Path $PSScriptRoot -Parent) 'install')
$exe        = Join-Path $InstallDir 'MyNotepad.exe'

if (-not (Test-Path $exe)) {
    throw "Executable not found: $exe. Run build.ps1 first."
}

$proc = Start-Process -FilePath $exe -WorkingDirectory $InstallDir -PassThru
Write-Output $proc.Id
# Emit a trailing blank line so that callers capturing stdout with
#   $out = & powershell -File launch.ps1
# receive a string[] (one element per line) rather than a single [string].
# With a lone line, $out is a [string] and $out[0] would be the first
# CHARACTER of the PID instead of the PID. The PID stays on the first line.
Write-Output ""