Rende dinamici path Python nei task
This commit is contained in:
@@ -9,6 +9,16 @@ param(
|
|||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
$repoRoot = Split-Path -Parent $PSScriptRoot
|
$repoRoot = Split-Path -Parent $PSScriptRoot
|
||||||
|
$pythonExe = (& python -c "import sys; print(sys.executable)").Trim()
|
||||||
|
|
||||||
|
if (-not $pythonExe -or -not (Test-Path -LiteralPath $pythonExe)) {
|
||||||
|
$pythonCommand = Get-Command python -ErrorAction Stop
|
||||||
|
$pythonExe = $pythonCommand.Source
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not (Test-Path -LiteralPath $pythonExe)) {
|
||||||
|
throw "Python executable not found. Run this script from the same shell where 'python' works."
|
||||||
|
}
|
||||||
|
|
||||||
if ($Task -eq "Notifier") {
|
if ($Task -eq "Notifier") {
|
||||||
$taskName = "$TaskFolder\ServerNotifierEvery30Minutes"
|
$taskName = "$TaskFolder\ServerNotifierEvery30Minutes"
|
||||||
@@ -24,6 +34,8 @@ if (-not (Test-Path -LiteralPath $xmlPath)) {
|
|||||||
|
|
||||||
$xml = Get-Content -LiteralPath $xmlPath -Raw
|
$xml = Get-Content -LiteralPath $xmlPath -Raw
|
||||||
$xml = $xml -replace 'encoding="UTF-8"', 'encoding="UTF-16"'
|
$xml = $xml -replace 'encoding="UTF-8"', 'encoding="UTF-16"'
|
||||||
|
$xml = $xml -replace '<Command>.*?</Command>', ('<Command>{0}</Command>' -f [System.Security.SecurityElement]::Escape($pythonExe))
|
||||||
|
$xml = $xml -replace '<WorkingDirectory>.*?</WorkingDirectory>', ('<WorkingDirectory>{0}</WorkingDirectory>' -f [System.Security.SecurityElement]::Escape($repoRoot))
|
||||||
|
|
||||||
$tempXml = Join-Path $env:TEMP ("bakrest-task-{0}.xml" -f ([Guid]::NewGuid()))
|
$tempXml = Join-Path $env:TEMP ("bakrest-task-{0}.xml" -f ([Guid]::NewGuid()))
|
||||||
[System.IO.File]::WriteAllText($tempXml, $xml, [System.Text.Encoding]::Unicode)
|
[System.IO.File]::WriteAllText($tempXml, $xml, [System.Text.Encoding]::Unicode)
|
||||||
@@ -34,6 +46,8 @@ try {
|
|||||||
throw "schtasks failed with exit code $LASTEXITCODE"
|
throw "schtasks failed with exit code $LASTEXITCODE"
|
||||||
}
|
}
|
||||||
Write-Host "Registered task: $taskName"
|
Write-Host "Registered task: $taskName"
|
||||||
|
Write-Host "Python: $pythonExe"
|
||||||
|
Write-Host "WorkingDirectory: $repoRoot"
|
||||||
} finally {
|
} finally {
|
||||||
Remove-Item -LiteralPath $tempXml -Force -ErrorAction SilentlyContinue
|
Remove-Item -LiteralPath $tempXml -Force -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user