How to avoid console window with .pyw file containing os.system call?

You should use subprocess.Popen class passing as startupinfo parameter’s value instance of subprocess.STARTUPINFO class with dwFlags attribute holding subprocess.STARTF_USESHOWWINDOW flag and wShowWindow attribute holding subprocess.SW_HIDE flag. This can be inferred from reading lines 866-868 of subprocess.py source code. It might be necessary to also pass subprocess.CREATE_NEW_CONSOLE flag as a value of creationflags parameter as you … Read more

Running a process in pythonw with Popen without a console

From here: import subprocess def launchWithoutConsole(command, args): “””Launches ‘command’ windowless and waits until finished””” startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW return subprocess.Popen([command] + args, startupinfo=startupinfo).wait() if __name__ == “__main__”: # test with “pythonw.exe” launchWithoutConsole(“d:\\bin\\gzip.exe”, [“-d”, “myfile.gz”]) Note that sometimes suppressing the console makes subprocess calls fail with “Error 6: invalid handle”. A quick fix is … Read more