PHP return_var 代码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2230523/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 05:38:44  来源:igfitidea点击:

PHP return_var codes?

phpexec

提问by Jeffrey Berthiaume

I'm testing the php exec command:

我正在测试 php exec 命令:

http://php.net/exec

http://php.net/exec

and I'm getting back a result code of 127.

我得到了 127 的结果代码。

My php code is:

我的php代码是:

<?

print "<br>executing 'hello':<br><b>";
exec ("hello", $output, $result);
var_dump($output);
print "<br>$result";
print "<br></b>end hello.";


print "<br><hr><br>";


print "<br>executing 'dir':<br><b>";
exec("dir", $output2, $result2);
var_dump($output2);
print "<br>$result2";
print "<br></b>end dir.";

?>

And the output is:

输出是:

executing 'hello':
array(0) { } 
127
end hello.


executing 'dir':
array(2) { [0]=> string(42) "bs1.jpg hello  index.htm ml1_1.jpg pp1.jpg" } 
0
end dir.

The php documentation (as far as I could find) says this:

php 文档(据我所知)是这样说的:

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.

返回变量

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

...but does not have a list of output possibilities or a way to look them up.

...但没有输出可能性的列表或查找它们的方法。

Any suggestions?

有什么建议?

采纳答案by Owen

Return codes can be a bit arbitrary. Basically though, any non-zero return value is an error. Here's a listof some common ones, but typically, unless you're working with a specific program, it's easier to just assume non-zero = some error was found, as opposed to trying to map a number of different programs to specific error codes.

返回码可能有点随意。基本上,任何非零返回值都是错误。是一些常见程序的列表,但通常,除非您使用特定程序,否则更容易假设非零 = 发现了某些错误,而不是尝试将许多不同程序映射到特定错误代码.

回答by Anthony Forloney

Return code 127 means The specified procedure could not be found.

返回码 127 表示找不到指定的过程。

Assuming you are on Windows, Windows System Error Codes

假设您使用的是 Windows,Windows 系统错误代码

回答by álvaro González

Return values are completely arbitrary. When you write a program you can make it return whatever value you want. In PHP, you can do it with the exitlanguage construct:

返回值是完全任意的。当你编写一个程序时,你可以让它返回任何你想要的值。在 PHP 中,您可以使用退出语言结构来实现:

<?php
exit(33);

You can find out the exact status code for a specific piece of software on its documentation (given that the author actually documented it). However, there's common agreement that 0 means "OK" and anything else means "there was a problem", so checking against zero is normally enough.

您可以在其文档中找到特定软件的确切状态代码(假设作者实际记录了它)。但是,普遍认为 0 表示“OK”,其他任何表示“存在问题”,因此检查零通常就足够了。

In you case, it looks like you are trying to execute a non-existing program. PHP executes external programs through the system shell so the value is likely to come from bash or whatever default shell you have. In Unix, there're some exit codes with special meaningsand 127means command not found.

在您的情况下,您似乎正在尝试执行一个不存在的程序。PHP 通过系统 shell 执行外部程序,因此该值可能来自 bash 或您拥有的任何默认 shell。在Unix中,有一些是有特殊含义的退出码127分的手段找不到命令

回答by Bruce Alderman

exec()operates on an external file, and receives the return code from there or from the operating system. If the 127 is coming from the operating system, it means the file wasn't found in your defined path.

exec()对外部文件进行操作,并从那里或从操作系统接收返回代码。如果 127 来自操作系统,则表示在您定义的路径中找不到该文件。

If, on the other hand, the 127 is coming from the application you're running, you would have to check the documentation for that app to know what it means.

另一方面,如果 127 来自您正在运行的应用程序,则您必须查看该应用程序的文档以了解它的含义。