Skip to content

Commit 8022cfa

Browse files
committed
Fix Windows installer Python detection
1 parent f0606d7 commit 8022cfa

1 file changed

Lines changed: 36 additions & 3 deletions

File tree

install-windows.ps1

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,40 @@ function Log($Message) {
3333
Write-Host "`n==> $Message" -ForegroundColor Cyan
3434
}
3535

36+
function Test-ShouldPauseOnExit {
37+
try {
38+
if (-not [Environment]::UserInteractive) { return $false }
39+
if ($Host.Name -ne 'ConsoleHost') { return $false }
40+
41+
$commandLine = Get-CimInstance Win32_Process -Filter "ProcessId = $PID" -ErrorAction Stop |
42+
Select-Object -ExpandProperty CommandLine
43+
if (-not $commandLine) { return $false }
44+
45+
return $commandLine -match '(?i)(^|\s)-(c|command|file|encodedcommand)\b'
46+
}
47+
catch {
48+
return $false
49+
}
50+
}
51+
52+
function Wait-BeforeExit {
53+
if (Test-ShouldPauseOnExit) {
54+
Write-Host ''
55+
Read-Host 'Press Enter to close this window' | Out-Null
56+
}
57+
}
58+
3659
function Die($Message) {
3760
Write-Host "Error: $Message" -ForegroundColor Red
61+
Wait-BeforeExit
3862
exit 1
3963
}
4064

4165
function Test-PythonCompatible($PythonPath) {
4266
try {
43-
$version = & $PythonPath -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")' 2>$null
67+
$version = & $PythonPath -c 'import sys; print(sys.version_info.major); print(sys.version_info.minor)' 2>$null
4468
if (-not $version) { return $false }
45-
$parts = $version.Split('.')
69+
$parts = @($version)
4670
$major = [int]$parts[0]
4771
$minor = [int]$parts[1]
4872
return ($major -gt $MinMajor) -or ($major -eq $MinMajor -and $minor -ge $MinMinor)
@@ -174,4 +198,13 @@ Done! Slicer URI Bridge is installed.
174198
"@
175199
}
176200

177-
Main
201+
try {
202+
Main
203+
}
204+
catch {
205+
$message = $_.Exception.Message
206+
if (-not $message) {
207+
$message = ($_ | Out-String).Trim()
208+
}
209+
Die $message
210+
}

0 commit comments

Comments
 (0)