starting programs from python script on windows

Benedict Verheyen benedict.verheyen at gmail.com
Mon Jan 28 04:32:06 EST 2008


Hi,


i want to automate starting programs on my windows machine and i want
to do it with windows.
This is a sample script:

from subprocess import Popen, PIPE
import time

print " Starting app 1"
time.sleep(1)
try:
     p1 = Popen(["C:\Program Files\Microsoft 
Office\OFFICE11\OUTLOOK.EXE"], stdout=PIPE)
except Exception, e:
     print "Error on startup app 1 %s " % str(e)

print " Starting app 2"
time.sleep(1)

try:
     p2 = Popen(["C:\Windows\system32\cmd.exe"], stdout=PIPE)
except Exception, e:
     print "Error on startup app 2 %s " % str(e)

It start it from a batch file:
SET PYTHONPATH=C:\Python25

rem - path to script to execute
%PYTHONPATH%\python.exe C:\login.py

This is the result:

C:\>C:\Python25\python.exe C:\login.py
  Starting app 1
  Starting app 2
Het proces heeft geprobeerd naar een niet-bestaande sluis te schrijven.
Het proces heeft geprobeerd naar een niet-bestaande sluis te schrijven.
Het proces heeft geprobeerd naar een niet-bestaande sluis te schrijven.

1. I get an error message saying the process has tried to write to a non 
existing pipe.

2. Order of execution isn't respected: it prints the 2 messages and then 
it tries to start the programs. Outlook is started but the command 
prompt not.

Anyway, if it works, i would like to start using python to drive the 
startup scripts of the users on the system.

How can i use python to start several programs as i would otherwise do 
manually and keep the order i want?

Thanks,
Benedict




More information about the Python-list mailing list