starting programs from python script on windows


B

Benedict Verheyen

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
 
Ad

Advertisements

P

Piet van Oostrum

Benedict Verheyen said:
BV> Hi,
BV> i want to automate starting programs on my windows machine and i want
BV> to do it with windows.
BV> This is a sample script:
BV> from subprocess import Popen, PIPE
BV> import time
BV> print " Starting app 1"
BV> time.sleep(1)
BV> try:
BV> p1 = Popen(["C:\Program Files\Microsoft Office\OFFICE11\OUTLOOK.EXE"],

Use raw strings or escape the \'s.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top