php exec返回状态为1

本文介绍如何正确使用 PHP 的 exec 函数,并通过实例演示如何排查返回状态为 1 的错误。文章还提供了 exec 函数的参数说明及返回状态详解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

之前在用到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 NumberMeaningExampleComments
1Catchall for general errorslet "var1 = 1/0"Miscellaneous errors, such as "divide by zero"
2Misuse of shell builtins (according to Bash documentation) Seldom seen, usually defaults to exit code 1
126Command invoked cannot execute Permission problem or command is not an executable
127"command not found" Possible problem with $PATH or a typo
128Invalid argument to exitexit 3.14159exit takes only integer args in the range 0 - 255 (see footnote)
128+nFatal error signal "n"kill -9 $PPID of script$? returns 137 (128 + 9)
130Script terminated by Control-C Control-C is fatal error signal 2, (130 = 128 + 2, see above)
255*Exit status out of rangeexit -1exit takes only integer args in the range 0 - 255
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值