I have two files: first.php:
#!/usr/bin/php
<?php
exit("Unable"); //1
#exit(1); //2
#exit(); //or exit(0) //3
?>
second.php:
#!/usr/bin/php
<?php
exec("./first.php",$out,$err);
var_dump($out);
echo "\n".$err;
?>
Now, When I run second.php with line #1 in first.php I have "Unable" in $out and 0 in $err. but with two other exits I have that digit in $err.
How can I have non-zero in $err when I execute exit with string message?
I have tested 2>&1 but it's useless.
A non-zero exit status indicates failure. This seemingly counter-intuitive scheme is used so there is one well-defined way to indicate success and a variety of ways to indicate various failure modes. When a command terminates on a fatal signal whose number is N , Bash uses the value 128+ N as the exit status.
To check the exit code we can simply print the $? special variable in bash. This variable will print the exit code of the last run command. $ echo $?
Exit status is an integer number. 0 exit status means the command was successful without any errors. A non-zero (1-255 values) exit status means command was a failure.
The echo command is used to display the exit code for the last executed Fault Management command.
exit("hi");
Is the same as:
echo "hi";
exit(0);
So just echo the statement :)
echo "Unable";
exit(2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With