2

How to start a program with Python?

I thougt this would be very easy like:

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

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

2
  • You should accept the answer that seems best. If more than one answer is good and right, you can still up-vote both of them. Commented Apr 23, 2010 at 12:31
  • 1
    WHichever one works better for you. If you just need to execute a command and wait until it's done, use call. If you need to get output from the command, feed it input, or have it run while your program continues (i.e. in parallel), use Popen. Commented Apr 23, 2010 at 12:32

3 Answers 3

13

In general you can do that 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 a page in a 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 .

Sign up to request clarification or add additional context in comments.

Comments

7

You are opening the file to read its content, instead try subprocess module

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

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

Comments

2

try os.system() and read up on alternatives in the subprocess module.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.