Exit () with message and non-zero exit status

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 outputs, I have this figure in $ err.

How can I get a nonzero value in $ err when I execute exit with a string message?
I tested 2> & 1, but it is useless.

+7
source share
5 answers
 exit("hi"); 

Same as:

 echo "hi"; exit(0); 

So just repeat the statement :)

 echo "Unable"; exit(2); 
+9
source

You cannot get the line termination code. The exit codes are integers.

0
source

You can exit with a string message and print it on standard output, but as for the exit code, this is an integer and the string will be converted to 0, which is a successful exit code.

0
source

You can even call a function on exit.

  function execute() { echo "whatever"; } exit(execute()); 
0
source

You can also use die("Unable");

0
source

All Articles