drv54591 2012-09-22 14:08
浏览 56
已采纳

exit()带有消息和非零退出状态

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 "
".$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.

  • 写回答

5条回答 默认 最新

  • dpaal28266 2012-09-22 14:15
    关注
    exit("hi");
    

    Is the same as:

    echo "hi";
    exit(0);
    

    So just echo the statement :)

    echo "Unable";
    exit(2);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?