run bat file without window code example
Example 1: how to run bat file without effect main code
import subprocess
from subprocess import Popen
import time
from multiprocessing import Process,freeze_support
def run_batfile(name='world'):
subprocess.call(["launch_pg.bat"])
if __name__ == '__main__':
p = Process(target=run_batfile)
p.start()
count = 0
while True:
count+=1
print(count)
time.sleep(1)
Example 2: windowless cmd
1. WIN-key + R --> %appdata%
2. create a new text document called "invisible.vbs"
3. With a text editor, edit "invisible.vbs". Paste the following line, then save and close:
CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False
4 create a new shortcut to run:
A) (command e.g. open paint): wscript.exe %appdata%invisible.vbs "CMD /k mspaint"
B) (run .bat file): wscript.exe %appdata%invisible.vbs "CMD /k C:\full\path\to\myFile.bat"