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?
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 . . ."
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With