kame
kame

Reputation: 21960

How to start a program with Python?

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.

Upvotes: 2

Views: 1241

Answers (3)

krawyoti
krawyoti

Reputation: 20135

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 .

Upvotes: 13

YOU
YOU

Reputation: 123801

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"])

Upvotes: 7

Daren Thomas
Daren Thomas

Reputation: 70314

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

Upvotes: 2

Related Questions