简体   繁体   English

使用Powershell自动执行以PAUSE结尾的bat文件

[英]Using Powershell to automating a bat file that ends with PAUSE

I have a batch file that I can't change, but I want to automate with Powershell 2.0. 我有一个无法更改的批处理文件,但是我想使用Powershell 2.0进行自动化。 It ends with a PAUSE command, which displays: 它以PAUSE命令结尾,该命令显示:

Press any key to continue...

Is there an way to call this batch file from a powershell script, but have it exit without needing a user to press something? 有没有一种方法可以从Powershell脚本中调用此批处理文件,但是无需用户按一下就可以退出它?

You can pipe anything into the cmd process: 您可以将任何内容通过管道传递到cmd进程:

'' | cmd /c foo.cmd

which will be treated as input by cmd and that's enough for pause to stop pausing. 这将被cmd视为输入,这足以使pause停止暂停。

Sample code here . 示例代码在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM