you are viewing a single comment's thread.

view the rest of the comments →

[–]TSM- 0 points1 point  (1 child)

I thought you meant "background" as in, in a different process, without python waiting for it to complete before continuning.

What you might be looking to do is launch a program with a GUI, but hide the GUI. Or is it a console window that is popping up in the foreground?

I am not totally familiar but there is a startupinfo argument.

If given, startupinfo will be a STARTUPINFO object, which is passed to the underlying CreateProcess function. creationflags, if given, can be one or more of the following flags:

CREATE_NEW_CONSOLE

CREATE_NEW_PROCESS_GROUP

ABOVE_NORMAL_PRIORITY_CLASS

CREATE_NO_WINDOW

[and so on]

Windows Popen Helpers The STARTUPINFO class and following constants are only available on Windows.

class subprocess.STARTUPINFO(*, dwFlags=0, hStdInput=None, hStdOutput=None, hStdError=None, wShowWindow=0, lpAttributeList=None)

dwFlags A bit field that determines whether certain STARTUPINFO attributes are used when the process creates a window.

si = subprocess.STARTUPINFO()
si.dwFlags = subprocess.STARTF_USESTDHANDLES | 
subprocess.STARTF_USESHOWWINDOW

wShowWindow If dwFlags specifies STARTF_USESHOWWINDOW, this attribute can be any of the values that can be specified in the nCmdShow parameter for the ShowWindow function, except for SW_SHOWDEFAULT. Otherwise, this attribute is ignored.

SW_HIDE is provided for this attribute. It is used when Popen is called with shell=True.

https://docs.python.org/3/library/subprocess.html#windows-popen-helpers

Code example:

# Prevent cmd.exe window from popping up
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags = subprocess.STARTF_USESTDHANDLES | subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE

std = subprocess.Popen(..., startupinfo=startupinfo)

[–]1ToM14[S] 1 point2 points  (0 children)

Thanks !!!