CMD pops up with os.syste() on Windows

Hi,

I have written a GUI that uses os.system() to call external programs. It works fine on Linux and OSX but on Windows (Vista) and empty Command Prompt window pops up for the duration of the system call. I use os.system() because I need the childprocess to interit the environmental variables set in the main program. Does anyone know how to avoid these pop-ups?

Kasper Munch

···


Department of Integrative Biology
University of California, Berkeley
Office phone: (510) 643-6299

Hello,

···

On Wed, Oct 1, 2008 at 2:40 PM, Kasper Munch kaspermunch@berkeley.edu wrote:

Hi,

I have written a GUI that uses os.system() to call external programs. It works fine on Linux and OSX but on Windows (Vista) and empty Command Prompt window pops up for the duration of the system call. I use os.system() because I need the childprocess to interit the environmental variables set in the main program. Does anyone know how to avoid these pop-ups?

Use subprocess.Popen instead. On windows pass it shell=False. You can pass then environment too env=os.environ

If the window still shows on Windows I have found the following works to make it go away as well.

STARTUPINFO = subprocess.STARTUPINFO()

STARTUPINFO.dwFlags |= subprocess.STARTF_USESHOWWINDOW

Then in the Popen call pass startupinfo=STARTUPINFO

Cody