How to Run an .exe File in Python

痞子三分冷 提交于 2019-12-08 03:11:54

问题


I am trying to run a .exe file in python2.7. I have tried everything I could from searching it. Here are some code I have tried:

subprocess.Popen(r"C:\Programs Files\Internet Explorer\iexplore.exe")

And:

subprocess.Popen(["cmd","/c",r"C:\Programs Files\Internet Explorer\iexplore.exe"])

And:

os.popen(r"C:\Programs Files\Internet Explorer\iexplore.exe")

All except the first one(which brings up a Windows Error) do not seem to run iexplore.exe.

Is there another way to run an .exe file?


回答1:


As Thomas explained in a comment, C:\Programs Files is not a standard directory on Windows. You could, of course, create a directory with that name, but it's unlikely that you've done so. Most likely you wanted C:\Program Files (notice Program vs. Programs).

The best way to avoid problems like this is to open the folder in Explorer, turn on the address bar, and copy and paste the path directly into your code. Then you'll know it's correct.

Also, you really should look at what the WindowsError says. It will almost certainly have some text about not being able to find such a file. Even if that doesn't help you, it would help people trying to solve your problem for you on a site like SO.




回答2:


If you just want to open the webbrowser, you could do this instead:

import webbrowser
webbrowser.open('www.google.com')


来源:https://stackoverflow.com/questions/19849868/how-to-run-an-exe-file-in-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!