Python OSError: [Errno 2] 没有那个文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1927284/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python OSError: [Errno 2] No such file or directory
提问by chrissygormley
I am trying to write this script to my linux terminal and I am recieving the following error message: "OSError: [Errno 2] No such file or directory". Can anyone help, Thanks
我正在尝试将此脚本写入我的 linux 终端,但收到以下错误消息:“OSError: [Errno 2] No such file or directory”。谁能帮忙,谢谢
#!/home/build/test/Python-2.6.4
import os, subprocess
# Create a long command line
cmd =[\
"si createsandbox --yes --hostname=be", \
" --port=70", \
" --user=gh", \
" --password=34", \
" --populate --project=e:/project.pj", \
" --lineTerminator=lf new_sandbox"\
]
outFile = os.path.join(os.curdir, "output.log")
outptr = file(outFile, "w")
errFile = os.path.join(os.curdir, "error.log")
errptr = file(errFile, "w")
retval = subprocess.call(cmd, 0, None, None, outptr, errptr)
errptr.close()
outptr.close()
if not retval == 0:
errptr = file(errFile, "r")
errData = errptr.read()
errptr.close()
raise Exception("Error executing command: " + repr(errData))
回答by YOU
If the error is in your script, May be you got error on this line
如果错误在您的脚本中,可能是您在此行中遇到错误
errptr = file(errFile, "r")
you can do like
你可以喜欢
if os.path.exists(errFile):
errptr = file(errFile, "r")
errData = errptr.read()
errptr.close()
raise Exception("Error executing command: " + repr(errData))
And also try with fullpath for command "si" like /usr/bin/si
instead of just si
并且还尝试对命令“si”使用完整路径,/usr/bin/si
而不仅仅是si
回答by Venchior
try modify like this:
尝试像这样修改:
cmd =[\
"si", \
" createsandbox --yes --hostname=be", \
" --port=70", \
" --user=gh", \
" --password=34", \
" --populate --project=e:/project.pj", \
" --lineTerminator=lf new_sandbox"\
]
I guset subprocess.call will think that the first parameter which in "" is a command
我 guset subprocess.call 会认为 "" 中的第一个参数是一个命令