# Inconsistent exit code from CLI?

- Thread: https://externals.io/message/49971
- Original archive: https://news-web.php.net/php.internals/49971
- Started by John Carter on 2010-10-26T08:29:17+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #49971 — John Carter — 2010-10-26T08:29:17+00:00

URL: https://externals.io/message/49971#49971

Hi,

When php is invoked from the command line with -h we get exit code 0 as
expected:

-bash-3.2# php -h ; echo $?
Usage: php [options] [-f] <file> [--] [args...]
       php [options] -r <code> [--] [args...]
       php [options] [-B <begin_code>] -R <code> [-E <end_code>] [--]
[args...]
...
  --re <name>      Show information about extension <name>.
  --ri <name>      Show configuration for extension <name>.

0

However if we use (what I understand to be an) invalid option we also
get 0:

php -Z ; echo $?
Usage: php [options] [-f] <file> [--] [args...]
....
0

I've checked a couple of other tools (ls and grep) and they return exit
code 2 when the options aren't recognised.

Found on 5.2.14 and 5.3.3.

Thanks,

John.

-- 
John Carter
Development Manager
johncart@cisco.com

---

## #49972 — Richard Quadling — 2010-10-26T10:59:59+00:00

URL: https://externals.io/message/49971#49972 · In reply to: #49971

> Hi,
>
> When php is invoked from the command line with -h we get exit code 0 as
> expected:
>
> -bash-3.2# php -h ; echo $?
> Usage: php [options] [-f] <file> [--] [args...]
>       php [options] -r <code> [--] [args...]
>       php [options] [-B <begin_code>] -R <code> [-E <end_code>] [--]
> [args...]
> ...
>  --re <name>      Show information about extension <name>.
>  --ri <name>      Show configuration for extension <name>.
>
> 0
>
> However if we use (what I understand to be an) invalid option we also
> get 0:
>
> php -Z ; echo $?
> Usage: php [options] [-f] <file> [--] [args...]
> ....
> 0
>
> I've checked a couple of other tools (ls and grep) and they return exit
> code 2 when the options aren't recognised.
>
> Found on 5.2.14 and 5.3.3.
>
> Thanks,
>
> John.

Using windows ...

@ECHO OFF
ECHO Calling PHP -v
PHP -v
ECHO %ERRORLEVEL%
ECHO Calling PHP -j
PHP -j
ECHO %ERRORLEVEL%

Both errorlevels are 0.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
