#Requires -Version 5.0 <# launch.ps1 - Launches the Notetask GUI application. Outputs ONLY the numeric process id (PID) as the first line on stdout, which the test harness reads to manage the process. Notetask is a native Win32 (Lazarus/LCL) desktop app - no sandbox flags or unique profile dirs are required. It has no single-instance lock, so the harness can relaunch it repeatedly without collisions. #> [CmdletBinding()] param( [string]$InstallDir = '' ) $ErrorActionPreference = 'Stop' # Some RB callers invoke this script through a wrapper where $PSScriptRoot is # empty while the default parameter expression is evaluated. Resolve the # script directory after parameter binding and fall back to the current # reference directory used by the harness. if ([string]::IsNullOrWhiteSpace($InstallDir)) { $ScriptDir = $PSScriptRoot if ([string]::IsNullOrWhiteSpace($ScriptDir) -and $MyInvocation.MyCommand.Path) { $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path } if ([string]::IsNullOrWhiteSpace($ScriptDir)) { $ScriptDir = (Get-Location).Path } $InstallDir = Join-Path (Split-Path $ScriptDir -Parent) 'install' } $exePath = Join-Path $InstallDir 'notetask.exe' if (-not (Test-Path $exePath)) { throw "Notetask executable not found at: $exePath" } # Launch with the install directory as the working directory so any settings # file (form_settings.json) lands next to the executable. $proc = Start-Process -FilePath $exePath -WorkingDirectory $InstallDir -PassThru Write-Output $proc.Id # IMPORTANT: emit a second (blank) line. The harness captures stdout with # $out = & powershell -File launch.ps1 # $appPid = [int]$out[0] # If this script prints only ONE line, PowerShell stores $out as a single # String and $out[0] indexes the first CHARACTER of the PID (wrong). Printing # a second line forces $out to be a string ARRAY, so $out[0] is the whole PID. # The PID remains the first line; do not remove this trailing line. Write-Output ""