fix: 隔离 Windows 节点标准输出
启动图形节点时重定向标准输出和错误,避免继承 trans 管道导致受控 CLI 丢失终态。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user