mirror of
https://github.com/vczh-libraries/Release.git
synced 2026-02-07 04:21:39 +08:00
36 lines
1.2 KiB
PowerShell
36 lines
1.2 KiB
PowerShell
function Start-Process-And-Wait([String[][]] $Pairs, [Boolean]$Inline = $false, [String]$workingDirectory = "") {
|
|
$processes = New-Object System.Diagnostics.Process[] $Pairs.Length
|
|
for ($i = 0; $i -lt $Pairs.Length; $i++) {
|
|
Write-Host " Running: $($Pairs[$i][0]) $($Pairs[$i][1])" -ForegroundColor DarkGray
|
|
|
|
$arguments = @{};
|
|
if ($Pairs[$i][1] -ne "") {
|
|
$arguments.Add("ArgumentList", $Pairs[$i][1])
|
|
}
|
|
$arguments.Add("PassThru", $true)
|
|
$arguments.Add("NoNewWindow", $Inline)
|
|
if ($workingDirectory -ne "") {
|
|
$arguments.Add("WorkingDirectory", $workingDirectory)
|
|
}
|
|
|
|
$processes[$i] = Start-Process $Pairs[$i][0] @arguments
|
|
}
|
|
|
|
$failed = $false
|
|
for ($i = 0; $i -lt $Pairs.Length; $i++) {
|
|
$process = $processes[$i]
|
|
$process_handle = $process.Handle
|
|
$process.WaitForExit()
|
|
if ($process.ExitCode -ne 0) {
|
|
Write-Host " Crashes($($process.ExitCode)): $($Pairs[$i][0]) $($Pairs[$i][1])" -ForegroundColor Red
|
|
$failed = $true
|
|
}
|
|
$process.Close()
|
|
}
|
|
|
|
[Console]::ResetColor()
|
|
|
|
if ($failed) {
|
|
throw "One or more processes crash"
|
|
}
|
|
} |