running applications in python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lee

    #1

    running applications in python

    how can i run or open a windows application from the python prompt?for
    e.g.mediaplayer opening,folder acess etc

  • Jordan

    #2
    Re: running applications in python

    os.system, os.spawn, the process module, os.popen[1,2,3,4], this is a
    pretty basic thing, not trying to be mean, but you should look in the
    python docs, this is definitely in there. Also, the subprocess module
    is meant to replace all of those but i haven't looked too closely at it
    yet, so the following might not be perfect.

    import subprocess as sp
    sp.call(['wmplayer.exe', 'some_args_prob ably_a_movie_na me'])

    you'll probably need to use the full path for media player, and the
    call() function is a simplified command within the subprocess module,
    useful if you don't really need to redirect input/output/errors or
    other aspects of the opened application. Also, you'll probably want
    something more like: retcode = sp.call(...), so that you can check the
    return code to see if it was successful. Check out the subprocess
    module.

    Cheers,
    Jordan

    On Jan 25, 12:28 pm, "lee" <libi...@gmail. comwrote:
    how can i run or open a windows application from the python prompt?for
    e.g.mediaplayer opening,folder acess etc

    Comment

    • Daniel

      #3
      Re: running applications in python

      2007-01-25 18:28:44
      lee <libintr@gmail. comwrote in message
      <1169746124.376 610.139420@13g2 000cwe.googlegr oups.com>
      how can i run or open a windows application from the python
      prompt?for
      e.g.mediaplayer opening,folder acess etc
      Here's another way of doing it:
      import os
      TheCommandIwant Torun = '"C:\Program\Wi ndows Media Player\wmplayer .
      exe"' #saves the command to a string
      os.system(TheCo mmandIwantTorun ) #runs TheCommandIwant Torun in the
      command prompt (windows)

      Comment

      Working...