php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17107 exit() always reports exit status=255
Submitted: 2002-05-08 21:44 UTC Modified: 2002-05-26 17:43 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: phpbug at robin dot pfft dot net Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.2.0 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: phpbug at robin dot pfft dot net
New email:
PHP Version: OS:

 

 [2002-05-08 21:44 UTC] phpbug at robin dot pfft dot net
$ php -v
4.2.0
$ php -q
<?php
exit(5);
?>
$ echo $?
255

exit(n) always reports 255 (or -1) as exit status to the OS, regardless of the value it is passed as argument.

The correct behavior according to the documentation would be to report n as exit status, or echo n if n is a string.

The only workaround I could find is to use return from the global scope.

Thank you :)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-05-10 02:06 UTC] derick@php.net
I think I broke this, so I'll fix it too :)

Derick
 [2002-05-13 13:47 UTC] dave at cc0 dot net
Experiencing same problem on 4.2.0/Linux. Return from global scope does not seem to work for me though or else I would use it as an alternative.

Is this fixed in CVS?

-Dave
 [2002-05-13 14:10 UTC] phpbug at robin dot pfft dot net
Here's another workaround for you if you have --enable-pcntl: 
 
$ php -q 
<?php 
pcntl_exec("/bin/sh", array("-c", "exit 123")); 
?> 
$ echo $? 
123
 [2002-05-13 14:57 UTC] dave at cc0 dot net
The pcntl_exec worked good...Thank you.

Ideally the exit status would work as discussed on the dev mailing list...exit(int) sets status as integer, exit(string) prints string.

just tested on PHP 4.3.0-dev (cli) and still no exit status...;)

Know where I should start hacking?? /sapi/cli ?

Thanks for the pcntl tip!

-Dave
 [2002-05-26 17:43 UTC] edink@php.net
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a documentation 
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 02:01:31 2024 UTC