PHP return_var codes?
I'm testing the php exec command:
http://php.net/exec
and I'm getting back a result code of 127.
My php code is:
<?
print "<br>executing 'hello':<br><b>";
exec ("hello", $o开发者_Python百科utput, $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:
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.
...but does not have a list of output possibilities or a way to look them up.
Any suggestions?
Return codes can be a bit arbitrary. Basically though, any non-zero return value is an error. Here's a list of 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.
Return code 127 means The specified procedure could not be found.
Assuming you are on Windows, Windows System Error Codes
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 exit language construct:
<?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.
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 meanings and 127 means command not found.
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.
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.
精彩评论