Skip to content Skip to sidebar Skip to footer

Call To Several Batch Files Through Cmd Doesn't Block

I'm trying to call several install.bat files one after another with Python trough CMD. It is necessary that each bat file be displayed in an interactive console window because it a

Solution 1:

The most common way to start a batch file (or more generally a CLI command) if to pass it as an argument to cmd /c. After you comment I can assume that you need to use start to force the creation of a (new) command window.

In that case the correct way is to add the /wait option to the start command: it will force the start command to wait the end of its subprocess:

subprocess.call("start /W cmd /C " + "Install.bat", cwd=os.path.join(gamesDosDir,game),
    shell=True)

But @eryksun proposed a far cleaner way. On Windows, .bat files can be executed without shell = True, and creationflags=CREATE_NEW_CONSOLE is enough to ensure a new console is created. So above line could simply become:

subprocess.call("Install.bat", cwd=os.path.join(gamesDosDir,game),
    creationflags = subprocess.CREATE_NEW_CONSOLE)

Post a Comment for "Call To Several Batch Files Through Cmd Doesn't Block"