php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36187 PHP-CLI does not return int exit status set by exit()
Submitted: 2006-01-28 05:24 UTC Modified: 2006-01-30 15:16 UTC
From: volker at puttrich dot net Assigned:
Status: Not a bug Package: CGI/CLI related
PHP Version: 5.1.2 OS: Debian Sarge
Private report: No CVE-ID: None
 [2006-01-28 05:24 UTC] volker at puttrich dot net
Description:
------------
The CLI version of PHP does not return the integer exit status to the shell when using 'exit(integer);' from within the script. PHP will always return 0 (or 255 probably).

The manual says that it would do.

Calling 'exit("string");' (with a string as parameter) it works as expected and as mentioned in the manual.

Reproduce code:
---------------
This is what I'm trying to do:

file1.php
---------
<?
system("php ./file2.php", $rv);
fwrite(STDOUT, $rv."\n");

system("php ./file2.php -- -param", $rv);
fwrite(STDOUT, $rv."\n");
?>

file2.php
---------
<?
if($argc < 2)
    exit(1);
else
    exit(0);
?>


Expected result:
----------------
Execute:

# php ./file1.php

Output should be:
1
0


Actual result:
--------------
Buggy result is:
0
0

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-29 16:12 UTC] sniper@php.net
Works fine for me:

# php t.php ; echo $?
222

t.php:
<?php exit(222); ?>

 [2006-01-30 15:16 UTC] volker at puttrich dot net
Thank you for your reply ...

I must admit that your example does work.

And I'm sorry, because even my own example works as one would expect. I didn't try it myself, because I assumed that it would NOT work. 

I'm using pretty much the same code in a larger application where it definately does NOT work. In that application I'm working a lot with 'exec()' and 'system()' and also using IO redirections. It might have to do with that, but I have not yet been able to isolate the real cause from within a smaller context.

So for now I'd say that you can close the issue. As soon as I know where the problem comes from, and it has to do with PHP, I'd happily re-open this issue if you don't mind.

Again, I'm really sorry that I wasted your time just because I made big mistake.

PHP-CLI is somewhat cool and I hope it will replace Perl some day, on Unix-like OS. Thanks for making it...

- Volker
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 23:01:28 2024 UTC