r/programminghelp • • Jan 16 '21

Python Make a .bat script run silently when started from a python script?

I know this is a very specific question, but how would I do this? I'm using batch files for multiple things in my program, mostly starting up multiple programs, using code such as this:

@echo off
start thisProgram.exe
start otherProgram.exe

First of all, I still get the little black command line window when I run this, which I thought 'echo off' disabled? Anyway, I found a workaround by generating a .vbs script, using this code:

Set WshShell = CreateObject("WScript.Shell")
WshShell.run chr(34) & "testBat.bat" & Chr(34), 0
Set WshShell = Nothing

When I run the .vbs normally, it works, no black command line box, and the programs that the .bat file specifies open immediately. However, if I try to start the .vbs from python, using os.system(), I still get the little black box, then the two programs start.

I suppose the bottom line of this is: How do I make a .bat file run without opening a command line window, when ran from python? Any help for this would be greatly appreciated! Thanks.

12 Upvotes

3 comments sorted by

1

u/llamanade1127 Jan 17 '21

Try making the python file extension .pyw . This should stop the console from opening