Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. It ends with a PAUSE command, which displays:

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?

like image 276
tenpn Avatar asked Aug 07 '10 10:08

tenpn


People also ask

Does pause work in PowerShell?

When the pause command is run, PowerShell will display the message "Press Enter to continue..." and then halt any further execution until the user presses the ENTER key on the keyboard. In Windows CMD the PAUSE command displays the message "Press any key to continue . . ."

How do I pause a BAT file execution?

You can insert the pause command before a section of the batch file that you might not want to process. When pause suspends processing of the batch program, you can press CTRL+C and then press Y to stop the batch program.

How do I pause a PowerShell script execution?

The pause command is very simple, and will display Press any key to continue . . . and remain that way until a key is pressed to resume execution. You may ask how to use this in a script, but just like you would any other command, insert the cmd /c 'pause' command within your script to utilize the native functionality.

Can you run a bat file in PowerShell?

To run the batch commands from PowerShell, we can use the Start-Process cmdlet as earlier explained and which executes a cmd command on the server.


1 Answers

You can pipe anything into the cmd process:

'' | cmd /c foo.cmd

which will be treated as input by cmd and that's enough for pause to stop pausing.

Sample code here.

like image 78
Joey Avatar answered Oct 02 '22 21:10

Joey