Skip to content

Commit 96501bd

Browse files
committed
Powershell: Create a Start-Process wrapper
1 parent 874cefa commit 96501bd

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

x.ps1

+8-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ function Get-Application($app) {
1414
return Get-Command $app -ErrorAction SilentlyContinue -CommandType Application
1515
}
1616

17+
function Invoke-Application($application, $arguments) {
18+
$process = Start-Process -NoNewWindow -PassThru $application $arguments
19+
$process.WaitForExit()
20+
Exit $process.ExitCode
21+
}
22+
1723
foreach ($python in "py", "python3", "python", "python2") {
1824
# NOTE: this only tests that the command exists in PATH, not that it's actually
1925
# executable. The latter is not possible in a portable way, see
@@ -23,17 +29,14 @@ foreach ($python in "py", "python3", "python", "python2") {
2329
# Use python3, not python2
2430
$xpy_args = @("-3") + $xpy_args
2531
}
26-
$process = Start-Process -NoNewWindow -PassThru $python $xpy_args
27-
$process.WaitForExit()
28-
Exit $process.ExitCode
32+
Invoke-Application $python $xpy_args
2933
}
3034
}
3135

3236
$found = (Get-Application "python*" | Where-Object {$_.name -match '^python[2-3]\.[0-9]+(\.exe)?$'})
3337
if (($null -ne $found) -and ($found.Length -ge 1)) {
3438
$python = $found[0]
35-
$process = Start-Process -NoNewWindow -Wait -PassThru $python $xpy_args
36-
Exit $process.ExitCode
39+
Invoke-Application $python $xpy_args
3740
}
3841

3942
Write-Error "${PSCommandPath}: error: did not find python installed"

0 commit comments

Comments
 (0)