python 2.6中没有spawnl函数?

发布于 2024-08-12 02:05:17 字数 468 浏览 4 评论 0原文

我刚刚注意到我用 python 2.5 编写的旧代码现在不起作用了。顺便说一句,我使用的是 python 2.6。

>>> os.spawnl(os.P_NOWAIT,"setup.exe")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\python26\lib\os.py", line 612, in spawnl
    return spawnv(mode, file, args)
OSError: [Errno 22] Invalid argument
>>>

有什么线索吗?或者您是否有 os.spawn* 的任何带有 NOWAIT 选项的工作示例。

更新:

即使我将完整路径放入 os.spawnl() 中,它仍然是错误。

I just noticed that my old codes written in python 2.5 does not work now. I am in python 2.6 btw.

>>> os.spawnl(os.P_NOWAIT,"setup.exe")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\python26\lib\os.py", line 612, in spawnl
    return spawnv(mode, file, args)
OSError: [Errno 22] Invalid argument
>>>

Any clue? or do you have any working sample of os.spawn* with NOWAIT option.

Update:

Even I put full path in os.spawnl(), Its still error.

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

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

发布评论

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

评论(5

浪漫人生路 2024-08-19 02:05:17

thrope 关于 subprocess 是首选的说法是正确的。但在 2.6 中,spawn* 的内容仍然存在。事实上,您可以在错误消息中看到这一点。你的第一个参数似乎是有效的。我会检查第二个参数,即路径。

thrope is right about subprocess being preferred. But the spawn* stuff is still there in 2.6. In fact, you can see that in your error message. Your first arg seems to be valid. I'd check the second arg, which is the path.

九局 2024-08-19 02:05:17

我最后通过添加 DUMMY 参数让它工作,虽然有点时髦

这不起作用

os.spawnl(os.P_NOWAIT,"Setup.exe")

这也不起作用

os.spawnl(os.P_NOWAIT,"Setup.exe","")

但这是工作

os.spawnl(os.P_NOWAIT,"Setup.exe","DUMMY")

无论如何谢谢大家。

I got it work by adding DUMMY parameter finally, a bit funky though

This is not working

os.spawnl(os.P_NOWAIT,"Setup.exe")

This is also not working

os.spawnl(os.P_NOWAIT,"Setup.exe","")

But this is working

os.spawnl(os.P_NOWAIT,"Setup.exe","DUMMY")

Thanks all anyway.

飘过的浮云 2024-08-19 02:05:17

我认为现在建议使用 subprocess 模块而不是 os .spawn* 函数。 (我无法重现你的问题,但我不在Windows上)。

I think its recommended to use the subprocess module these days rather than the os.spawn* functions. (I can't reproduce your problem, but I'm not on windows).

贱人配狗天长地久 2024-08-19 02:05:17

Google 搜索会显示此页面,当其中有空格时会发生相同的问题Python 安装路径。我无法在这里重现它,但这也许就是问题所在?

无论如何,根据 MS 文档仅当模式参数无效时才应返回此错误值 (EINVAL),但此处的情况并非如此。

A Google search brings up this page about the same problem happening when there is a space in the Python installation path. I couldn't reproduce it here, but maybe it's the problem?

In any case, according to MS documentation this error value (EINVAL) should only be returned if the mode argument is invalid, which isn't the case here.

羁绊已千年 2024-08-19 02:05:17

os.spawnl() 需要可执行文件的完整路径,而 os.spawnlp() 使用 PATH 环境变量来查找它。

更新:在路径文字中使用未转义的反斜杠也是常见错误(尝试打印它以查看它是否被正确解释)。

os.spawnl() requires full path to executable, while os.spawnlp() uses PATH environment variable to find it.

Update: Also it's common error to use unescaped backslashes in the path literal (try printing it to see whether it's interpreted right).

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