Merge pull request #1697 from pikasTech/fix/hwpod-node-desktop-stdio
Pipelines as Code CI / hwlab-web-probe-sentinel-nc01- Success
Pipelines as Code CI / unidesk-host- Success

fix: 隔离 Windows 节点标准输出
This commit is contained in:
Lyon
2026-07-10 19:15:33 +08:00
committed by GitHub
+6 -2
View File
@@ -442,6 +442,7 @@ function applyDesktop(spec: HwpodNodeSpec, artifact: ArtifactBundle, credential:
scriptPath: spec.runtime.scriptPath,
configPath: spec.runtime.configPath,
credentialPath: spec.runtime.credentialPath,
logPath: spec.runtime.logPath,
probeLauncherPath: spec.python.probeLauncherPath,
guiLauncherPath: spec.python.guiLauncherPath,
launcherArgs: spec.python.launcherArgs,
@@ -565,6 +566,7 @@ $root = [string]$payload.runtimeRoot
$scriptPath = [string]$payload.scriptPath
$configPath = [string]$payload.configPath
$credentialPath = [string]$payload.credentialPath
$logPath = [string]$payload.logPath
$probe = [string]$payload.probeLauncherPath
$gui = [string]$payload.guiLauncherPath
$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" }
$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 ' | ')" }
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) })
foreach ($proc in $old) { Stop-Process -Id $proc.ProcessId -Force -ErrorAction SilentlyContinue }
Start-Sleep -Milliseconds 500
@@ -588,7 +590,9 @@ $argText = (($launcherArgs | ForEach-Object { '"' + ($_ -replace '"','\"') + '"'
$runCommand = '"' + $gui + '" ' + $argText + ' "' + $scriptPath + '"'
$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
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
$processes = @(Get-CimInstance Win32_Process | Where-Object { $_.CommandLine -and $_.CommandLine.Contains($scriptPath) })
$explorerSessions = @(Get-Process explorer -ErrorAction SilentlyContinue | Select-Object -ExpandProperty SessionId -Unique)