[CmdletBinding()] param( [Parameter(Mandatory=$true)][string]$ExecutableName, [Parameter(Mandatory=$true)][string[]]$ExecutableArguments, [Parameter(Mandatory=$true)][string]$LogStem ) $ErrorActionPreference = 'Stop' $RoundDir = [IO.Path]::GetFullPath($PSScriptRoot) $StandaloneRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..\..\..')) if ([IO.Path]::GetFileName($ExecutableName) -ne $ExecutableName) { throw 'ExecutableName must be a filename.' } if ([IO.Path]::GetFileName($LogStem) -ne $LogStem) { throw 'LogStem must be a filename stem.' } $ExecutablePath = Join-Path (Join-Path $StandaloneRoot 'bin') $ExecutableName if (-not (Test-Path -LiteralPath $ExecutablePath -PathType Leaf)) { throw "Executable not found: $ExecutablePath" } $StdoutPath = Join-Path $RoundDir ($LogStem + '.stdout.log') $StderrPath = Join-Path $RoundDir ($LogStem + '.stderr.log') $HostProcess = Get-Process -Id $PID $HostProcess.PriorityClass = 'Normal' $HostProcess.ProcessorAffinity = [IntPtr]0xFFFF $Child = Start-Process -FilePath $ExecutablePath -ArgumentList $ExecutableArguments ` -WorkingDirectory $StandaloneRoot -WindowStyle Hidden -PassThru ` -RedirectStandardOutput $StdoutPath -RedirectStandardError $StderrPath $PeakWorkingSet = 0L while (-not $Child.HasExited) { $Child.Refresh() if ($Child.HasExited) { break } $Child.PriorityClass = 'Normal' $Child.ProcessorAffinity = [IntPtr]0xFFFF $PeakWorkingSet = [Math]::Max($PeakWorkingSet,$Child.WorkingSet64) Start-Sleep -Milliseconds 500 } $Child.WaitForExit() $Child.Refresh() Write-Output "RUN_EXIT pid=$($Child.Id) priority=Normal affinity=0xFFFF peak_process_gb=$([math]::Round($PeakWorkingSet/1GB,2)) exit_code=$($Child.ExitCode)" exit $Child.ExitCode