什么是PHP的exec()返回值? [英] What is the PHP exec() return value?

查看:808
本文介绍了什么是PHP的exec()返回值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用PHP的exec()函数。

I am trying to use the PHP exec() function.


如果return_var参数和输出参数一起出现,
,则执行命令的返回状态将被写入此
变量。

If the return_var argument is present along with the output argument, then the return status of the executed command will be written to this variable.

,它是0.然而,如果有一个错误,它可以是多个其他整数。我似乎找不到那些整数对应的地方。我应该如何解释我获得的整数?

If the execution was successful, it's 0. However, if there is an error, it can be a multitude of other integers. I can't seem to find anywhere what those integers correspond to. How should I interpret the integer that I get?

更新

真的应该指定这本来,但我正在执行另一个PHP脚本。不像rsync,它的手册页上有退出值,我找不到PHP的等价物。

I really should have specified this originally, but I am executing another PHP script. Unlike rsync, which has exit values on its man page, I can't find an equivalent for PHP.

所以我做的是:

$rv = exec('php file.php', $out, $rv);


推荐答案

返回值取决于进程/程序你用exec运行。例如,如果你运行grep:

The return value is dependent on the process/program that you ran with exec. For instance, if you ran grep:


如果找到选择的行,退出状态为0,如果不是
,退出状态为1 。如果出现错误,退出状态为2.(注意:POSIX
错误处理代码应检查是否为2或更大。)

The exit status is 0 if selected lines are found, and 1 if not found. If an error occurred the exit status is 2. (Note: POSIX error handling code should check for '2' or greater.)


$ b b

rsync有大约20个不同的错误退出代码,都在man页面中进行了详细解释:

rsync has about 20 different error exit codes, all painstakingly explained in the man page:

http://linux.die.net/man/1/rsync

所以是的,它是程序相关的: )

so yes, it's program-dependant :)

即使您正在运行PHP脚本,退出值也取决于您的程序本身。默认情况下php脚本将以0.退出。如果你使用退出函数,你可以返回不同的退出代码:

Even if you're running PHP script, the exit value depends on your program itself. By default php scripts will exit with 0. If you use the exit function you can return different exit codes:

http://php.net/manual/en/function.exit.php

如果您想实验确定你的php程序退出,在命令行上调用它:

If you want to experimentally determine what your php program exits, call it on the command line:

php file.php

然后执行

echo $?

这将显示您的php脚本的退出值。

this will show you the exit value of your php script.

这篇关于什么是PHP的exec()返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆