I am trying to run an executable from python using subprocess.call(), see the code below. However, the executable has a GUI which pops up whenever it is called. I don't need to see the executable window and so I would like it to just open in the background. Note, that the variable tool below is the name of the executable and chdir_file is the required input file for the executable. Is there a way to stop the called program from popping up and instead opening in the background?
subprocess.call('"' + tool + '"' + " /R: " + '"' + chdir_file + '"')
Please note that the command window is not shown when I execute the above code, only the executable window. I have seen a lot about how to hide the command window during this command but not about how to hide the called program. Here are some of the things I have tried:
1)
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
subprocess.call('"' + tool + '"' + " /R: " + '"' + chdir_file + '"', startupinfo=si)
Result: partially successful This opens the executable windows in the background but removes the cursor from the currently active window, which I would like not to happen.
2)
CREATE_NO_WINDOW = 0x08000000
subprocess.call('"' + tool + '"' + " /R: " + '"' + chdir_file + '"', creationflags=CREATE_NO_WINDOW)
Result - no change: No command window, but the executable window still pops up in the screen foreground.
3)
DETACHED_PROCESS = 0x00000008
subprocess.call('"' + tool + '"' + " /R: " + '"' + chdir_file + '"', creationflags=DETACHED_PROCESS)
Result - no change: Same as number (2) - No command window, but the executable window still pops up in the screen foreground.
4)
subprocess.call('"' + tool + '"' + " /R: " + '"' + chdir_file + '"', shell=True)
Result - no change: Same as number (2) & (3) - No command window, but the executable window still pops up in the screen foreground.
5)
subprocess.call("start " + '"' + tool + '"' + " /B" + " /R: " + '"' + chdir_file + '"')
Result - no change: Same as number (2) & (3) & (4) - No command window, but the executable window still pops up in the screen foreground.
Thanks in advance!