如何在Python中运行.exe文件 [英] How to Run an .exe File in Python

查看:182
本文介绍了如何在Python中运行.exe文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在python2.7中运行.exe文件.我已经尝试了所有可能的搜索方法.这是我尝试过的一些代码:

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

并且:

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.

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

还有另一种方法来运行.exe文件吗?

Is there another way to run an .exe file?

推荐答案

正如Thomas在评论中所解释的,C:\Programs Files不是Windows上的标准目录.当然,您可以使用该名称创建目录,但是您不太可能这样做.您最有可能想要C:\Program Files(注意ProgramPrograms).

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.

此外,您真的应该看看WindowsError的内容.几乎可以肯定会有一些关于找不到这样的文件的文字.即使这样对您没有帮助,也可以帮助尝试在SO之类的网站上为您解决问题的人们.

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.

这篇关于如何在Python中运行.exe文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆