1

Hello all I am new to asking questions on websites like this, so please help me out if I go astray (or if clarification is needed). Here goes:

I have built a python script that successfully launches a program as a new process (or subprocess? is that a real thing?) in Windows 7. The program, and its GUI, open and run a specific text file, and when complete the resulting data is saved out to a .csv and the program and process are terminated. The relevant python code is below:

import subprocess
import os
pw_directory = r"C:\Program Files (x86)\..." #directory of theProgram.exe
master_directory = r"C:\Users\...." #path to the .txt file that is executed in theProgram.exe
os.chdir(pw_directory)
my_process = subprocess.Popen([r"theProgram.exe", master_directory])

My question is: is there a way to suppress the program's GUI interface when it is launched as a new process? I just want to load the .txt file and execute it in the background as there is no reason to interface with the GUI since everything is automated.

In an effort to make the question general, I have not included theProgram.exe name, though this may be necessary information. Not sure. Thanks for any advice.

wassup_doc
  • 21
  • 1
  • 5
  • 1
    it doesn't answer your question, but it is related: [How do I hide the console when I use os.system() or subprocess.call()?](http://stackoverflow.com/q/7006238/4279) – jfs Sep 02 '13 at 18:34
  • Definitely related, correct me if I am wrong though... It seems in this case they are trying to suppress the command line window that pops up when executing a program or script. Would this apply to suppressing the actual program's GUI interface? – wassup_doc Sep 02 '13 at 19:36
  • yes, `startupinfo` is used to hide the console. I don't know whether a similar technique could be used to suppress the actual program's window (probably not). – jfs Sep 03 '13 at 02:43

1 Answers1

1

Some windows programs allow them to be run from the command line with the GUI suppressed it varies between programs.

Either check the specific programs website/help/manuals/usergroups or try running from the command line with the -h -? -help or --help flags - those that do allow it normally have command line help - and look for a quiet option, (often -q --quiet or --silent are used).

Also some programs are actually GUI front ends for command line back end processing so there may be a different command to run on the command line altogether - the documents are usually the place to look for that.

Sorry this is effectively a long version of RTFM but there is really no completely general answer that I know of.

Update

This answer (from J.F. Sebastian's comment) put me on the track of:

startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = SW_HIDE # i.e. 0 you could also try 11 SW_FORCEMINIMIZE
subprocess.call(["theProgram.exe", etc], startupinfo = startupinfo)

This looks to do what you need.

Community
  • 1
  • 1
Steve Barnes
  • 27,618
  • 6
  • 63
  • 73
  • I will get in contact with the program's administrators. The program itself is a GUI front-end with a proprietary scripting language that does everything "under-the-hood." Perhaps there is a command that I have missed. I am just surprised there is not a general way to run any program in windows "in the background." – wassup_doc Sep 02 '13 at 20:01
  • Microsoft never provided one that I ever heard of it is up to the individual developers. There are a few tricks that will work with some programs. You could also look for "run minimised" as an option. – Steve Barnes Sep 03 '13 at 04:54