Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable 'pause' in windows bat script

In windows, I am running a bat script that currently ends with a 'pause' and prompts for the user to 'Press any key to continue...'

I am unable to edit the file in this scenario and I need the script to terminate instead of hang waiting for input that will never come. Is there a way I can run this that will disable or circumvent the prompt?

I have tried piping in input and it does not seem to help. This script is being run from python via subprocess.Popen.

like image 895
Dillon Avatar asked Jul 30 '12 21:07

Dillon


People also ask

What does @echo off do?

The ECHO-OFF command suppresses echoing for the terminal attached to a specified process. The ECHO-ON command restores input echoing for a specified process. These commands are frequently used in Procs.

How do I make a batch file stay open?

If you're creating a batch file and want the MS-DOS window to remain open, add PAUSE to the end of your batch file. This prompts the user to Press any key. Until the user presses any key, the window remains open instead of closing automatically.


2 Answers

Try to execute cmd.exe /c YourCmdFile < nul

YourCmdFile - full path to your batch script

like image 151
Maximus Avatar answered Sep 27 '22 18:09

Maximus


subprocess.call("mybat.bat", stdin=subprocess.DEVNULL)

Would call mybat.bat and redirect input from nul on windows (which disables pause as shown in other answers)

like image 21
Bryce Guinta Avatar answered Sep 27 '22 18:09

Bryce Guinta