[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

starting programs from python script on windows

Benedict Verheyen

1/28/2008 9:32:00 AM

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

1 Answer

Piet van Oostrum

1/30/2008 8:00:00 AM

0

>>>>> Benedict Verheyen <benedict.verheyen@gmail.com> (BV) wrote:

>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.
--
Piet van Oostrum <piet@cs.uu.nl>
URL: http://pietvano... [PGP 8DAE142BE17999C4]
Private email: piet@vanoostrum.org