【问题标题】:Force PowerShell to press any key强制 PowerShell 按任意键
【发布时间】: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


【解决方案1】:

编辑:

尝试使用发送键: https://technet.microsoft.com/en-us/library/ff731008

希望对你有帮助

【讨论】:

  • 他想自动点击,而不是要求另一个
  • 这模拟了按键但 PowerShell 仍然等待批处理文件完成其工作。
猜你喜欢
  • 2020-03-14
  • 2012-08-06
  • 2020-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-29
相关资源
最近更新 更多