running applications in python

L

lee

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

Jordan

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_probably_a_movie_name'])

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
 
D

Daniel

2007-01-25 18:28:44
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
TheCommandIwantTorun = '"C:\Program\Windows Media Player\wmplayer.
exe"' #saves the command to a string
os.system(TheCommandIwantTorun) #runs TheCommandIwantTorun in the
command prompt (windows)
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top