python 2.6中没有spawnl函数?
我刚刚注意到我用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
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.我最后通过添加 DUMMY 参数让它工作,虽然有点时髦
这不起作用
这也不起作用
但这是工作
无论如何谢谢大家。
I got it work by adding DUMMY parameter finally, a bit funky though
This is not working
This is also not working
But this is working
Thanks all anyway.
我认为现在建议使用 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).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.
os.spawnl() 需要可执行文件的完整路径,而 os.spawnlp() 使用 PATH 环境变量来查找它。
更新:在路径文字中使用未转义的反斜杠也是常见错误(尝试打印它以查看它是否被正确解释)。
os.spawnl()
requires full path to executable, whileos.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).