In my python script:
p = Popen('a.bat')
The problem is that the output of the batch file is put to main console window in which I executed my python script... I want the output of the batch file to be shown in new console window. Any help would be appreciated. Thanks.
A batch file runs like any other executable file by double-clicking the file within Windows.
You can set the CREATE_NEW_CONSOLE
flag. For example:
import subprocess
p = subprocess.Popen('a.bat', creationflags=subprocess.CREATE_NEW_CONSOLE)
The docs regarding shell=True
are inconsistent with 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.
I haven't used python before, so I can't test, but this should work
p = Popen('cmd.exe /k start a.bat')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With