2

我正在尝试在 python2.7 中运行一个 .exe 文件。我已经尽我所能搜索它。这是我尝试过的一些代码:

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

和:

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

和:

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

除了第一个(引发 Windows 错误)之外的所有文件似乎都没有运行 iexplore.exe。

还有其他方法可以运行 .exe 文件吗?

4

2 回答 2

8

如果您只想打开网络浏览器,您可以这样做:

import webbrowser
webbrowser.open('www.google.com')
于 2013-11-08T01:21:17.710 回答
5

正如 Thomas 在评论中解释的那样,C:\Programs Files它不是 Windows 上的标准目录。当然,您可以创建一个具有该名称的目录,但您不太可能这样做。很可能您想要C:\Program Files(通知ProgramPrograms。)。

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.

于 2013-11-08T01:33:17.783 回答