之前在用到php exec 时 总是保存,返回状态1,那这时怎么排查呢
exec('ls 2>&1', $output, $return_val);
print_r($output);
使用 2>&1, 命令就会输出shell执行时的错误到$output变量, 输出该变量即可分析。
备注: exec有3个参数,第一个是要执行的命令,第二个是参数是一个数组,数组的值是由第一个命令执行后生成的,第三个参数执行的状态,0表示成功,其他都表示失败。
附:返回状态详解
Table D-1.
"Reserved" Exit Codes
Exit Code Number | Meaning | Example | Comments |
---|---|---|---|
1 | Catchall for general errors | let "var1 = 1/0" | Miscellaneous
errors, such as |
2 | Misuse of shell builtins (according to Bash documentation) | | Seldom
seen, usually defaults to exit code |
126 | Command invoked cannot execute | | Permission problem or command is not an executable |
127 | "command not found" | | Possible
problem with |
128 | Invalid
argument to | exit 3.14159 | exit |
128+n | Fatal
error signal | kill -9 | $? |
130 | Script terminated by Control-C | | Control-C
is fatal error signal |
255* | Exit status out of range | exit | exit |