Python(Portable 2.5)子进程报问题“WindowsError: [Error 3] The system can not find the path specified”

发布于 2024-11-16 11:01:23 字数 388 浏览 5 评论 0原文

我正在使用 python,代码在非便携式版本上都运行良好。因为我需要在一些不属于我的计算机上运行该程序,该计算机没有安装 python 或可用的此类选项。 我用便携式 python 代替。然而,以前运行良好的代码现在报告错误“WindowsError:[错误3]系统找不到指定的路径”。我在电脑上查了一下。运行顺利,没有出现上述错误。有人可以提供线索吗?

我使用的cmd是:

p = subprocess.Popen(self.cmdStr, shell=False, stdout=subprocess.PIPE, stderr=file)

我将stderr重定向到我指定的文件。

我也在网上google了一下。似乎存在“子进程路径语义和可移植性”的问题。我不确定是否是这个原因。请帮忙。谢谢。

I am using python and the codes are all worked well with non-portable version. Since I need to run the program on some computer that does not belong to me, which does not have installed python or such option available.
I use portable python instead. However the codes previously works well now report error"WindowsError: [Error 3] The system cannot find the path specified". I checked it on my computer. It works smoothly without the above error. Anybody can give a clue?

The cmd I am using is :

p = subprocess.Popen(self.cmdStr, shell=False, stdout=subprocess.PIPE, stderr=file)

I am redirecting the stderr to a file I specified.

I also googled online. There seems to have an issue of "subprocess PATH semantics and portability". I am not sure whether this is the reason. Please help. Thank you.

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

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

发布评论

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

评论(3

为你拒绝所有暧昧 2024-11-23 11:01:23

啊,问题出在 cmdStr 变量上。您必须使用绝对路径,否则让运行进程的用户拥有适当设置的 PATH 系统变量。或者您有 shell=False,这可能会导致子进程模块出现问题。检查文档中有关路径等的问题。

Ah, the problem is in the cmdStr variable. You must use absolute paths, or else have the user the process is running under have an appropriately setup PATH system variable. That or you have shell=False, which can cause problems in the subprocess module. Check the documentation for issues concerning paths etc.

微凉 2024-11-23 11:01:23

'cmd /c cmdstr' 可以在 Windows 上正确运行吗?

Can 'cmd /c cmdstr' run correctly on windows?

九八野马 2024-11-23 11:01:23

subprocess.Popen(r"C:\Python27\python.exe",shell=True) 可以正常工作。

subprocess.Popen(r"C:\Python27\python.exe",shell=True) can work correctly.

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