From eb1aa5600f9ce71f1e9b7dc89b122bc060db2ef6 Mon Sep 17 00:00:00 2001 From: ali Date: Thu, 19 Nov 2026 18:30:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(menu):=20=E9=98=9F=E5=88=97=E5=86=85?= =?UTF-8?q?=E6=94=B9=E7=94=A8=E7=8B=AC=E7=AB=8B=E5=AD=90=E8=BF=9B=E7=A8=8B?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=EF=BC=8C=E4=BF=AE=E5=A4=8D=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E4=B8=8D=E5=8F=AF=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 进程内调用 + '| Out-Host' 会让远端 ssh -t 的输出按行缓冲,'请选择分类' 这类不带换行的提示不会渲染,用户只能盲输(实测被误按 q 取消,归档全被取消) - 改为 Start-Process -NoNewWindow -Wait,子进程直接继承控制台,提示与 输入回显恢复正常;退出码取自子进程 ExitCode - media-archive 取消时返回 2 而不是 0,避免上层把「取消」记成「成功」 - worker 启动日志补充 stdin/stdout 是否被重定向,便于排查同类问题 --- scripts/explorer-media-rename.ps1 | 24 ++++++++++++++++-------- scripts/media_archive.py | 4 ++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/scripts/explorer-media-rename.ps1 b/scripts/explorer-media-rename.ps1 index 46324db..0e69a34 100644 --- a/scripts/explorer-media-rename.ps1 +++ b/scripts/explorer-media-rename.ps1 @@ -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 '' diff --git a/scripts/media_archive.py b/scripts/media_archive.py index a465afe..55981a1 100644 --- a/scripts/media_archive.py +++ b/scripts/media_archive.py @@ -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)