[英]linux command produce Python OSError: [Errno 2] No such file or directory
I have a problem... 我有个问题...
import sys
import subprocess
subprocess.call(['traceroute -I www.yahoo.com'])
and I had try 我试过了
import sys
import subprocess
subprocess.call(['/usr/sbin/traceroute -I www.yahoo.com'])
why I am recieving the following error message: "OSError: [Errno 2] No such file or directory". 为什么我收到以下错误消息:“OSError:[Errno 2]没有这样的文件或目录”。 Can anyone help...thanks! 谁能帮忙......谢谢!
I hate to answer without knowing the much about the underlying reasons, but I've run into this before with subprocess. 我不想在不知道底层原因的情况下回答,但我在使用子进程之前遇到过这种情况。 The call arguments list really wants a list -- I assume it is looking for an executable with spaces in the name, exactly matching what you enter. 调用参数列表确实需要一个列表 - 我假设它正在查找名称中带有空格的可执行文件,与您输入的内容完全匹配。 Try this instead: 试试这个:
import subprocess
subprocess.call(['traceroute', 'www.yahoo.com'])
import sys
import subprocess
subprocess.call('traceroute -I www.yahoo.com',shell=True)
You can simply do this with shell=True
option. 您可以使用shell=True
选项执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.