fix(menu): 队列内改用独立子进程执行,修复交互提示不可见

- 进程内调用 + '| Out-Host' 会让远端 ssh -t 的输出按行缓冲,'请选择分类'
  这类不带换行的提示不会渲染,用户只能盲输(实测被误按 q 取消,归档全被取消)
- 改为 Start-Process -NoNewWindow -Wait,子进程直接继承控制台,提示与
  输入回显恢复正常;退出码取自子进程 ExitCode
- media-archive 取消时返回 2 而不是 0,避免上层把「取消」记成「成功」
- worker 启动日志补充 stdin/stdout 是否被重定向,便于排查同类问题
This commit is contained in:
ali
2026-11-19 18:30:27 +08:00
parent 0e82f054ad
commit eb1aa5600f
2 changed files with 18 additions and 10 deletions
+16 -8
View File
@@ -149,14 +149,21 @@ function Invoke-Action([string]$itemAction, [string]$target) {
$runnerPath = Join-Path $PSScriptRoot $plan.Runner
$tokens = @($target) + $plan.Extra
# 注意:必须 Out-Host 把子脚本的输出导到控制台,
# 否则它会混进本函数的返回值,调用方拿到的就不是退出码了。
if ($DryRun) { & $runnerPath -Tokens $tokens -DryRun | Out-Host }
else { & $runnerPath -Tokens $tokens | Out-Host }
# 关键:用独立子进程「继承当前控制台」来跑,而不是在进程内 + 管道。
# 管道会让远端 ssh -t 的交互提示与本地输入回显错位(提示行会消失)。
$quotedTokens = ($tokens | ForEach-Object { "'" + ($_ -replace "'", "''") + "'" }) -join ','
$quotedRunner = "'" + ($runnerPath -replace "'", "''") + "'"
$extra = ''
if ($DryRun) { $extra = ' -DryRun' }
$command = "& $quotedRunner -Tokens @($quotedTokens)$extra"
$code = $LASTEXITCODE
if ($null -eq $code -or $code -is [array]) { return 0 }
return [int]$code
$proc = Start-Process -FilePath $PwshPath `
-ArgumentList @('-NoLogo', '-NoProfile', '-ExecutionPolicy', 'Bypass',
'-Command', ('"' + $command + '"')) `
-NoNewWindow -Wait -PassThru
if ($null -eq $proc) { return 1 }
return [int]$proc.ExitCode
}
# ---------------------------------------------------------------- worker 模式
@@ -171,7 +178,8 @@ function Invoke-Worker {
}
try { $Host.UI.RawUI.WindowTitle = 'SceneMarshal 队列' } catch { }
Write-WorkerLog 'worker 启动'
Write-WorkerLog ("worker 启动(stdin重定向={0} stdout重定向={1})" -f `
[Console]::IsInputRedirected, [Console]::IsOutputRedirected)
Write-Host '📋 SceneMarshal 队列已启动(空闲 20 秒后自动关闭)' -ForegroundColor Cyan
Write-Host ''
+2 -2
View File
@@ -426,7 +426,7 @@ def main() -> int:
category = choose_category(cats, suggestion)
if not category:
print("已取消。")
return 0
return 2 # 用非 0 退出码,避免上层把「取消」当成「成功」
dest = MEDIA_ROOT / category / src.name
merging = dest.exists() and not args.no_merge
@@ -460,7 +460,7 @@ def main() -> int:
confirm = "n"
if confirm not in {"", "y", "yes"}:
print("已取消。")
return 0
return 2 # 同上:取消不能报成成功
if merging:
rep = merge_into(src, dest)