开发者

How to start a program with Python?

开发者 https://www.devze.com 2022-12-27 18:12 出处:网络
How to start a program with Python? I thougt this would be very easy like: open(r\"C:\\Program Files\\Mozilla Firefox\\Firefox.exe\")

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 happe开发者_运维百科ns. How to do this? Thanks in advance.


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 .


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号