【发布时间】:2016-06-03 10:30:37
【问题描述】:
我有一个调用批处理脚本的 PowerShell 脚本(我无法更改批处理脚本的内容)。批处理脚本完成后提示Press any key to continue...,我必须手动按键。
PowerShell 脚本示例:
Start-Process script1.bat -NoNewWindow -Wait #this prompts 'Press any key...'
Start-Process script2.bat -NoNewWindow -Wait
如何强制 PowerShell 按任意键,以便它可以继续执行以下命令?
【问题讨论】:
-
会认为这是不可能的。在出现
Press any key...提示符时,所有控制都将在被调用的脚本中。即使有可能你怎么知道什么时候“按键”是合适的。我愿意被证明是错误的 -
我希望有一个等价的批次
call script.bat < nul -
试试
start-process "cmd /c echo; | script1.bat" -nonewwindow -wait。这应该在批处理脚本中添加一个换行符,并可能满足批处理脚本的pause。 -
@rojo 此行抛出
InvalidOperation: (:) [Start-Process], InvalidOperationException,我仍在搜索:... 但是,我创建了一个调用call script1.bat < nul的批处理脚本。我可以忍受。 -
我遇到了同样的问题,我的解决方案是将批处理文件复制到工作目录并从我的副本中删除暂停。它没有回答 OPs 的问题,但它可能是一个可行的解决方案。 (Get-Content "$workingDir\script.bat").replace('@pause', '') |设置内容“$workingDir\script.bat”
标签: powershell batch-file