Merge pull request #1697 from pikasTech/fix/hwpod-node-desktop-stdio
fix: 隔离 Windows 节点标准输出
This commit is contained in:
@@ -442,6 +442,7 @@ function applyDesktop(spec: HwpodNodeSpec, artifact: ArtifactBundle, credential:
|
|||||||
scriptPath: spec.runtime.scriptPath,
|
scriptPath: spec.runtime.scriptPath,
|
||||||
configPath: spec.runtime.configPath,
|
configPath: spec.runtime.configPath,
|
||||||
credentialPath: spec.runtime.credentialPath,
|
credentialPath: spec.runtime.credentialPath,
|
||||||
|
logPath: spec.runtime.logPath,
|
||||||
probeLauncherPath: spec.python.probeLauncherPath,
|
probeLauncherPath: spec.python.probeLauncherPath,
|
||||||
guiLauncherPath: spec.python.guiLauncherPath,
|
guiLauncherPath: spec.python.guiLauncherPath,
|
||||||
launcherArgs: spec.python.launcherArgs,
|
launcherArgs: spec.python.launcherArgs,
|
||||||
@@ -565,6 +566,7 @@ $root = [string]$payload.runtimeRoot
|
|||||||
$scriptPath = [string]$payload.scriptPath
|
$scriptPath = [string]$payload.scriptPath
|
||||||
$configPath = [string]$payload.configPath
|
$configPath = [string]$payload.configPath
|
||||||
$credentialPath = [string]$payload.credentialPath
|
$credentialPath = [string]$payload.credentialPath
|
||||||
|
$logPath = [string]$payload.logPath
|
||||||
$probe = [string]$payload.probeLauncherPath
|
$probe = [string]$payload.probeLauncherPath
|
||||||
$gui = [string]$payload.guiLauncherPath
|
$gui = [string]$payload.guiLauncherPath
|
||||||
$launcherArgs = @($payload.launcherArgs | ForEach-Object { [string]$_ })
|
$launcherArgs = @($payload.launcherArgs | ForEach-Object { [string]$_ })
|
||||||
@@ -572,7 +574,7 @@ if (-not (Test-Path $probe)) { throw "Python probe launcher missing: $probe" }
|
|||||||
if (-not (Test-Path $gui)) { throw "Python GUI launcher missing: $gui" }
|
if (-not (Test-Path $gui)) { throw "Python GUI launcher missing: $gui" }
|
||||||
$versionOut = @(& $probe @launcherArgs -c "import sys;import tkinter;print(sys.version);print(sys.executable);print(tkinter.TkVersion)" 2>&1)
|
$versionOut = @(& $probe @launcherArgs -c "import sys;import tkinter;print(sys.version);print(sys.executable);print(tkinter.TkVersion)" 2>&1)
|
||||||
if ($LASTEXITCODE -ne 0 -or (($versionOut -join "\`n") -notlike "*$($payload.expectedVersionPrefix)*")) { throw "Python version mismatch: $($versionOut -join ' | ')" }
|
if ($LASTEXITCODE -ne 0 -or (($versionOut -join "\`n") -notlike "*$($payload.expectedVersionPrefix)*")) { throw "Python version mismatch: $($versionOut -join ' | ')" }
|
||||||
New-Item -ItemType Directory -Force -Path $root, (Split-Path -Parent $configPath), (Split-Path -Parent $credentialPath) | Out-Null
|
New-Item -ItemType Directory -Force -Path $root, (Split-Path -Parent $configPath), (Split-Path -Parent $credentialPath), (Split-Path -Parent $logPath) | Out-Null
|
||||||
$old = @(Get-CimInstance Win32_Process | Where-Object { $_.CommandLine -and $_.CommandLine.Contains($scriptPath) })
|
$old = @(Get-CimInstance Win32_Process | Where-Object { $_.CommandLine -and $_.CommandLine.Contains($scriptPath) })
|
||||||
foreach ($proc in $old) { Stop-Process -Id $proc.ProcessId -Force -ErrorAction SilentlyContinue }
|
foreach ($proc in $old) { Stop-Process -Id $proc.ProcessId -Force -ErrorAction SilentlyContinue }
|
||||||
Start-Sleep -Milliseconds 500
|
Start-Sleep -Milliseconds 500
|
||||||
@@ -588,7 +590,9 @@ $argText = (($launcherArgs | ForEach-Object { '"' + ($_ -replace '"','\"') + '"'
|
|||||||
$runCommand = '"' + $gui + '" ' + $argText + ' "' + $scriptPath + '"'
|
$runCommand = '"' + $gui + '" ' + $argText + ' "' + $scriptPath + '"'
|
||||||
$null = New-Item -Path 'HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Run' -Force
|
$null = New-Item -Path 'HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Run' -Force
|
||||||
Set-ItemProperty -Path 'HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Run' -Name ([string]$payload.runKeyName) -Value $runCommand
|
Set-ItemProperty -Path 'HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Run' -Name ([string]$payload.runKeyName) -Value $runCommand
|
||||||
Start-Process -FilePath $gui -ArgumentList @($launcherArgs + @($scriptPath)) -WorkingDirectory $root
|
$stdoutPath = $logPath + '.stdout'
|
||||||
|
$stderrPath = $logPath + '.stderr'
|
||||||
|
Start-Process -FilePath $gui -ArgumentList @($launcherArgs + @($scriptPath)) -WorkingDirectory $root -RedirectStandardOutput $stdoutPath -RedirectStandardError $stderrPath
|
||||||
Start-Sleep -Seconds 3
|
Start-Sleep -Seconds 3
|
||||||
$processes = @(Get-CimInstance Win32_Process | Where-Object { $_.CommandLine -and $_.CommandLine.Contains($scriptPath) })
|
$processes = @(Get-CimInstance Win32_Process | Where-Object { $_.CommandLine -and $_.CommandLine.Contains($scriptPath) })
|
||||||
$explorerSessions = @(Get-Process explorer -ErrorAction SilentlyContinue | Select-Object -ExpandProperty SessionId -Unique)
|
$explorerSessions = @(Get-Process explorer -ErrorAction SilentlyContinue | Select-Object -ExpandProperty SessionId -Unique)
|
||||||
|
|||||||
Reference in New Issue
Block a user