From 7fe3320c901e2ff3ffb52e9999c60056a46558e0 Mon Sep 17 00:00:00 2001 From: Christian Schulze Date: Thu, 17 Feb 2022 17:10:10 +0100 Subject: [PATCH] hide console window if pythonw.exe is used improve comment --- src/subprocess_helper.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/subprocess_helper.py b/src/subprocess_helper.py index f2b0ecb1..e981b3a7 100644 --- a/src/subprocess_helper.py +++ b/src/subprocess_helper.py @@ -4,6 +4,14 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, """Call the given command(s).""" assert isinstance(commands, list) process = None + + popen_kwargs = {} + if sys.platform == "win32": + # This hides the console window if pythonw.exe is used + startupinfo = subprocess.STARTUPINFO() + startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW + popen_kwargs["startupinfo"] = startupinfo + for command in commands: try: dispcmd = str([command] + args) @@ -11,7 +19,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, process = subprocess.Popen([command] + args, cwd=cwd, env=env, stdout=subprocess.PIPE, stderr=(subprocess.PIPE if hide_stderr - else None)) + else None), **popen_kwargs) break except OSError: e = sys.exc_info()[1]