LambdaFox
LambdaFox

Reputation: 19

How to run a program without waiting for return code?

I am using Python 3.3. I have tried this:

# beginning and ending quotes are to compensate for Microsoft kludge
emuleappfile = '"'+os.environ['ProgramFiles']+'\\eMule\\emule.exe'+'"'
os.system(emuleappfile)
# vvv beginning and ending quotes are to compensate for Microsoft kludge
vuzeappfile = '"'+os.environ['ProgramFiles']+'\\Vuze\\azureus.exe'+'"'
os.system(vuzeappfile )

and this

# beginning and ending quotes are to compensate for Microsoft kludge
emuleappfile = '"'+os.environ['ProgramFiles']+'\\eMule\\emule.exe'+'"'
itran = os.system(emuleappfile)
# vvv beginning and ending quotes are to compensate for Microsoft kludge
vuzeappfile = '"'+os.environ['ProgramFiles']+'\\Vuze\\azureus.exe'+'"'
itran = os.system(vuzeappfile)

emule opens, but the program does not open vuze until after emule has been closed. grr.

Upvotes: 1

Views: 564

Answers (2)

Eryk Sun
Eryk Sun

Reputation: 34280

Use subprocess.Popen. On Windows this calls the Win32 API function CreateProcess.

http://docs.python.org/3/library/subprocess

import os
import subprocess

emuleappfile = os.path.join(os.environ['ProgramFiles'], 'eMule', 'emule.exe')
vuzeappfile = os.path.join(os.environ['ProgramFiles'], 'Vuze', 'azureus.exe')
proc_emule = subprocess.Popen([emuleappfile])
proc_vuze = subprocess.Popen([vuzeappfile])

Edit:

Popen exposes a few fields of the STARTUPINFO structure for setting process and window properties. See the section Windows Popen Helpers in the subprocess documentation. For example, use the following to start vuze in a hidden window, which will also be the window's default state for Win32 ShowWindow:

si = subprocess.STARTUPINFO()
si.dwFlags = subprocess.STARTF_USESHOWWINDOW
si.wShowWindow = subprocess.SW_HIDE
proc_vuze = subprocess.Popen([vuzeappfile], startupinfo=si)

Upvotes: 2

D K
D K

Reputation: 5760

os.system(''.join(['start "', os.environ['ProgramFiles'], '\\eMule\\emule.exe', '"'])) (specifically the start part) will run the executable in a separate window, therefore not blocking the current one.

Upvotes: 0

Related Questions