Disable 'pause' in windows bat script

This one turned out to be a bit of a pain. The redirect of nul from Maximus worked great, thanks!

As for getting that to work in python, it came down to the following. I started with:

BINARY = "C:/Program Files/foo/bar.exe"
subprocess.call([BINARY])

Tried to add the redirection but subprocess.call escapes everything too well and we loose the redirect.

subprocess.call([BINARY + " < nul"])
subprocess.call([BINARY, " < nul"])
subprocess.call([BINARY, "<", "nul"])

Using shell=True didn't work because the space in BINARY made it choke trying to find the executable.

subprocess.call([BINARY + " < nul"], shell=True)

In the end, I had to resort back to os.system and escape myself to get the redirection.

os.system(quote(BINARY) + " < nul")

Not ideal, but it gets the job done.

If anyone knows how to get the last subprocess example to work with the space in the binary, it would be much apprecated!


Try to execute cmd.exe /c YourCmdFile < nul

YourCmdFile - full path to your batch script


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)