当调用execl(…)时,我得到一个errno=2。这是什么意思?我怎么知道这个errno的意思?
当前回答
它的意思是:
未找到文件或目录。
其他回答
错误码2表示“未找到文件/目录”。通常,可以使用perror函数打印人类可读的字符串。
我使用以下脚本:
#!/usr/bin/python
import errno
import os
import sys
toname = dict((str(getattr(errno, x)), x)
for x in dir(errno)
if x.startswith("E"))
tocode = dict((x, getattr(errno, x))
for x in dir(errno)
if x.startswith("E"))
for arg in sys.argv[1:]:
if arg in tocode:
print arg, tocode[arg], os.strerror(tocode[arg])
elif arg in toname:
print toname[arg], arg, os.strerror(int(arg))
else:
print "Unknown:", arg
在shell中输入sudo apt-get install moreutils,然后,一旦安装完成,输入errno 2。您还可以对所有错误编号使用errno -l,或者通过将其输送到grep只查看文件编号,如下所示:errno -l | grep file。
我在我的.bashrc文件中有以下函数-它从头文件中查找errno值(可以是/usr/include/errno.h, /usr/include/linux/errno.h,等等,等等)
如果头文件安装在机器上,它就可以工作;-)
通常头文件有一个错误+接下来是注释中的解释;以下内容:
./asm-generic/errno-base.h:#define EAGAIN 11 /*重试*/
function errno()
{
local arg=$1
if [[ "x$arg" == "x-h" ]]; then
cat <<EOF
Usage: errno <num>
Prints text that describes errno error number
EOF
else
pushd /usr/include
find . -name "errno*.h" | xargs grep "[[:space:]]${arg}[[:space:]]"
popd
fi
}
这比在errno.h中查找代码要快,比这里发布的大多数解决方案都要短,并且不需要安装第三方工具:
perl -E 'say $!2 =转变'
收益率
没有这样的文件或目录