Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start a program with Python?

Tags:

python

load

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.

like image 671
kame Avatar asked Dec 30 '25 07:12

kame


2 Answers

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 .

like image 129
krawyoti Avatar answered Jan 01 '26 20:01

krawyoti


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"])
like image 36
YOU Avatar answered Jan 01 '26 22:01

YOU



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!