Windows 错误和 python

发布于 2024-07-24 11:03:01 字数 619 浏览 8 评论 0原文

我正在编写一些代码,这些代码应该在我的系统上的文件夹内运行 exe 文件,但收到错误消息...

WindowsError: [Error 3] 系统找不到指定的路径。 下面是一些代码:

exepath = os.path.join(EXE file localtion)
exepath = '"' + os.path.normpath(exepath) + '"'
cmd = [exepath, '-el', str(el), '-n', str(z)]

print 'The python program is running this command:'
print cmd

process = Popen(cmd, stderr=STDOUT, stdout=PIPE)
outputstring = process.communicate()[0]

我已经导入了子进程,也从子进程导入 *

例如,这是我的 exe 文件位置在我显示的代码的第一行中的样子:

 exepath= os.path.join('/Program Files','next folder','next folder','blah.exe')

我错过了什么吗?

I'm working on a bit of code that is supposed to run an exe file inside a folder on my system and getting an error saying...

WindowsError: [Error 3] The system cannot find the path specified.
Here's a bit of the code:

exepath = os.path.join(EXE file localtion)
exepath = '"' + os.path.normpath(exepath) + '"'
cmd = [exepath, '-el', str(el), '-n', str(z)]

print 'The python program is running this command:'
print cmd

process = Popen(cmd, stderr=STDOUT, stdout=PIPE)
outputstring = process.communicate()[0]

I have imported subprocess and also from subprocess import *

For example, This is how my exe file location looks like in the first line of the code I show:

 exepath= os.path.join('/Program Files','next folder','next folder','blah.exe')

Am I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

苦笑流年记忆 2024-07-31 11:03:01

您需要正确转义可执行路径中的空格

You need to properly escape the space in the executable path

再可℃爱ぅ一点好了 2024-07-31 11:03:01

除了正确转义空格和其他可能导致问题的字符(例如 /)之外,您还可以使用 8 个字符的旧 DOS 路径。

例如,程序文件将为:

Progra~1 ,确保为最后两个字符附加 ~1 。

编辑:您可以在字符串前面添加一个 r ,使其成为原始文字。 Python 会逐个字符地读取字符串。 像这样:

r“\程序文件”

Besides properly escaping spaces and other characters that could cause problems (such as /), you can also use the 8 character old DOS paths.

For example, Program Files would be:

Progra~1 , making sure to append ~1 for the last two characters.

EDIT: You could add an r to the front of the string, making it a raw literal. Python would read the string character for character. Like this:

r " \Program files"

把回忆走一遍 2024-07-31 11:03:01

如果我没记错的话,您不需要像第二行那样引用可执行文件路径。

编辑:嗯,只是抓住附近的 Windows 盒子并测试了这一点。 无论路径是否被引用,Popen 的工作方式都是相同的。 所以这不是问题。

If I remember correctly, you don't need to quote your executuable file path, like you do in the second line.

EDIT: Well, just grabbed nearby Windows box and tested this. Popen works the same regardless the path is quoted or not. So this is not an issue.

好多鱼好多余 2024-07-31 11:03:01

AFAIK,除非运行程序涉及 cmd.exe ,否则不需要将路径用引号引起来。

此外,您可能需要使用环境变量 ProgramFiles 来找出“Program Files”的实际位置,因为这取决于区域设置,并且也可以使用 TweakUI 进行调整。

AFAIK, there is no need to surround the path in quotation marks unless cmd.exe is involved in running the program.

In addition, you might want to use the environment variable ProgramFiles to find out the actual location of 'Program Files' because that depends on regional settings and can also be tweaked using TweakUI.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文