Disable pause in windows bat script

On Windows, I run a bat script that currently ends with a โ€œpauseโ€ and prompts the user to โ€œPress any key to continue ...โ€

I cannot edit the file in this script, and I need a script to complete, and not to wait for input that will never appear. Is there a way to run this to disable or bypass the invitation?

I tried connecting to the input and it does not seem to help. This script is launched from python via subprocess.Popen.

+7
source share
4 answers

Try to execute cmd.exe /c YourCmdFile < nul

YourCmdFile - the full path to your batch script

+13
source

It turned out to be a little painful. Maximus redirect nul did a great job, thanks!

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

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

Tried to add a redirect, but subprocess.call does it all too well and we lose the redirect.

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

Using shell = True did not work, because the space in BINARY made him try to find the executable.

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

In the end, I had to go back to os.system and avoid myself in order to get a redirect.

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

Not perfect, but he does his job.

If anyone knows how to get the latest example of a sub-process for working with space in binary format, it will be very appreciated!

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

Calling mybat.bat and redirecting input from nul to windows (which disables pause, as shown in other answers)

+4
source

The following code works for me:

 p = Popen("c:\script.bat <nul", cwd="c:\") 
0
source

Source: https://habr.com/ru/post/921718/


All Articles