starting programs from python script on windows

Discussion in 'Python' started by Benedict Verheyen, Jan 28, 2008.

  1. 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
     
    Benedict Verheyen, Jan 28, 2008
    #1
    1. Advertising

  2. >>>>> Benedict Verheyen <> (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 <>
    URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
    Private email:
     
    Piet van Oostrum, Jan 30, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kluchen

    starting programs

    kluchen, Aug 4, 2003, in forum: C++
    Replies:
    1
    Views:
    315
    Victor Bazarov
    Aug 4, 2003
  2. Replies:
    12
    Views:
    1,702
    Dave Thompson
    Jan 10, 2005
  3. Coca
    Replies:
    7
    Views:
    775
    Aidan Grey
    Aug 24, 2004
  4. lone_eagle
    Replies:
    3
    Views:
    669
    psykeedelik
    May 26, 2009
  5. Jeffrey Bowen

    starting another programs from inside.

    Jeffrey Bowen, Aug 20, 2007, in forum: Ruby
    Replies:
    3
    Views:
    96
    Ari Brown
    Aug 20, 2007
Loading...

Share This Page