How do I run a program using Python?

How do I run a program using Python?

It would be very easy for me:

open(r"C:\Program Files\Mozilla Firefox\Firefox.exe")

      

But nothing happens. How to do it? Thanks in advance.

+2


a source to share


3 answers


In general, you can do this using subprocess.call

>>> from subprocess import call
>>> call(r"C:\Program Files\Mozilla Firefox\Firefox.exe")

      

But if all you want to do is open the page in the browser you can do:



>>> import webbrowser
>>> webbrowser.open('http://stackoverflow.com/')
True

      

See http://docs.python.org/library/subprocess.html and http://docs.python.org/library/webbrowser.html .

+13


a source


You open the file to read its contents, try the subprocess module instead

http://docs.python.org/library/subprocess.html



import subprocess
subprocess.Popen([r"C:\Program Files\Mozilla Firefox\Firefox.exe"])

      

+7


a source


try os.system()

and read the alternatives in the module subprocess

.

+2


a source







All Articles