forked from mtusi2026/mtusi2026lab7
12 lines
965 B
PowerShell
12 lines
965 B
PowerShell
# Run a long command as a separate Windows process that survives the calling shell/session.
|
|
# powershell -File scripts/bg.ps1 -Log evidence/run.log -Cmd "docker compose up -d --build --wait"
|
|
# The command runs in Git Bash (same syntax as the Makefile/hooks); the exit code is the last
|
|
# line of the log ("exit=N"). Nothing secret is printed by the commands used with it.
|
|
param([Parameter(Mandatory)][string]$Log, [Parameter(Mandatory)][string]$Cmd)
|
|
$bash = Join-Path $env:ProgramFiles "Git\bin\bash.exe"
|
|
$root = Split-Path -Parent $PSScriptRoot
|
|
$logPath = if ([IO.Path]::IsPathRooted($Log)) { $Log } else { Join-Path $root $Log }
|
|
New-Item -ItemType Directory -Force (Split-Path -Parent $logPath) | Out-Null
|
|
$inner = "cd '$($root -replace '\\','/')' && export PYTHONUTF8=1 && { $Cmd ; } > '$($logPath -replace '\\','/')' 2>&1; echo exit=`$? >> '$($logPath -replace '\\','/')'"
|
|
Start-Process -FilePath $bash -ArgumentList @('-lc', "`"$inner`"") -WindowStyle Hidden
|