-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresolve_python.ps1
More file actions
46 lines (42 loc) · 1.55 KB
/
Copy pathresolve_python.ps1
File metadata and controls
46 lines (42 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function Resolve-PythonExe {
$pythonExe = $null
$pyLauncher = Get-Command py -ErrorAction SilentlyContinue
if ($pyLauncher) {
$pythonExe = & py -c "import sys; print(sys.executable)"
}
if (-not $pythonExe) {
$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
if ($pythonCmd) {
$pythonExe = & python -c "import sys; print(sys.executable)"
}
}
return $pythonExe
}
function Resolve-PythonwExe {
# Returns the windowless executable to use for a scheduled-task action, and
# whether it is the py-launcher's pyw.exe (as opposed to the console
# interpreter's own pythonw.exe sibling).
#
# pyw.exe is resolved as a sibling of the py launcher's own directory
# (typically C:\Windows\pyw.exe), not via `Get-Command pyw`, because that
# can resolve to a WindowsApps alias whose target is not guaranteed to be
# the same install that a `py -c ...` dependency check exercises.
param(
[Parameter(Mandatory = $true)]
[string]$PythonExe
)
$pywPath = $null
$pyLauncher = Get-Command py -ErrorAction SilentlyContinue
if ($pyLauncher) {
$pyDir = Split-Path $pyLauncher.Source
$candidate = Join-Path $pyDir "pyw.exe"
if (Test-Path $candidate) {
$pywPath = $candidate
}
}
if ($pywPath) {
return [PSCustomObject]@{ Exe = $pywPath; UsingPyw = $true }
}
$pythonwPath = Join-Path (Split-Path $PythonExe) "pythonw.exe"
return [PSCustomObject]@{ Exe = $pythonwPath; UsingPyw = $false }
}