Python: how can I execute a bat file in a new cmd window?

In my python script:

p = Popen('a.bat') 

The problem is that the output of the batch file is placed in the main console window in which I executed my python script ... I want the output of the batch file to appear in a new console window. Any help would be greatly appreciated. Thanks.

+6
source share
2 answers

You can set the flag CREATE_NEW_CONSOLE . For instance:

 import subprocess p = subprocess.Popen('a.bat', creationflags=subprocess.CREATE_NEW_CONSOLE) 

Documents regarding shell=True do not match the implementation . If you specify shell=True , it sets CREATE_NEW_CONSOLE only if the platform is either Win9x or uses the 16-bit COMMAND.COM shell.

+7
source

I haven't used python before, so I can't verify, but this should work

 p = Popen('cmd.exe /k start a.bat') 
+2
source

All Articles