In Windows, add startupinfo to subprocess calls to prevent terminal windows from opening in the background

This commit is contained in:
Micah Lee 2020-02-13 15:33:08 -08:00
parent 400b8d2b83
commit 791d930a55
No known key found for this signature in database
GPG key ID: 403C2657CD994F73
3 changed files with 21 additions and 3 deletions

View file

@ -341,3 +341,11 @@ class Common(object):
pass
return pdf_viewers
def get_subprocess_startupinfo(self):
if platform.system() == "Windows":
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
return startupinfo
else:
return None

View file

@ -28,7 +28,11 @@ def is_docker_installed(common):
def is_docker_ready(common):
# Run `docker ps` without an error
try:
subprocess.run([common.container_runtime, "ps"], check=True)
subprocess.run(
[common.container_runtime, "ps"],
check=True,
startupinfo=common.get_subprocess_startupinfo(),
)
return True
except subprocess.CalledProcessError:
return False
@ -36,7 +40,9 @@ def is_docker_ready(common):
def launch_docker_windows():
docker_desktop_path = "C:\\Program Files\\Docker\\Docker\\Docker Desktop.exe"
subprocess.Popen([docker_desktop_path])
subprocess.Popen(
[docker_desktop_path], startupinfo=common.get_subprocess_startupinfo()
)
class DockerInstaller(QtWidgets.QDialog):
@ -278,7 +284,10 @@ class Installer(QtCore.QThread):
elif platform.system() == "Windows":
try:
# Run the installer
subprocess.run([self.installer_filename])
subprocess.run(
[self.installer_filename],
startupinfo=common.get_subprocess_startupinfo(),
)
self.install_finished.emit()
except Exception as e:

View file

@ -31,6 +31,7 @@ class TaskBase(QtCore.QThread):
stderr=subprocess.PIPE,
bufsize=1,
universal_newlines=True,
startupinfo=self.common.get_subprocess_startupinfo(),
) as p:
if watch == "stdout":
pipe = p.stdout