PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » System » System_Command » Bug #6268

execute() raises SYSTEM_COMMAND_STDERR error when command exits non-zero

Details

Submitted2005-12-16 18:29 UTC
Fromcconstantine at php dot net
Assignedcconstantine
StatusClosed
PackageSystem_Command
PHP VersionIrrelevant
OS*nix
Roadmaps(Not assigned)

Comments

[2005-12-16 18:29 UTC] cconstantine at php dot net

Description:
------------
The execute() method behaves backwards/oddly:

- a command which writes to stderr and returns zero
does NOT raise SYSTEM_COMMAND_STDERR (nor any other
error.) This is "odd".

- a command which does NOT write to sderr, but DOES
return non-zero does raises SYSTEM_COMMAND_STDERR
This is simply wrong.

Furthermore, the output captured from stderr is not used for
anything, nor is it obtainable by the caller.

Test script:
---------------
TEST ONE...

<?php
require_once 'System/Command.php';
$cmd =& new System_Command;

// a simple command which does not write to stderr,
// but which does return a non-zero exit value
$cmd->pushCommand('exit','1');

$res = $cmd->execute();
if ( PEAR::isError($res) ) {
print("'".$res->getMessage()."'\n");
} else {
print("ok!\n");
}
?>

TEST TWO...

<?php
require_once 'System/Command.php';
$cmd =& new System_Command;

// A command which DOES write to stderr, and exits
// with zero return value.
$cmd->pushCommand('/usr/bin/logger','-s','hello world');

$res = $cmd->execute();
if ( PEAR::isError($res) ) {
print("'".$res->getMessage()."'\n");
} else {
print("ok!\n");
}
?>

Expected result:
----------------
TEST ONE...

Should raise some error which actually represents that the
command returned non-zero. Fix the error code/message.

TEST TWO...

Should raise some error which represents that the exit value
is zero, but that there was output on stderr. Add a new error
code and way to get at the output from stderr -- but for
backcompat execute() should NOT raise an error if the return
value is zero (regardless of stderr output.)

Actual result:
--------------
TEST ONE...

The test code outputs "'System_Command Error: command wrote to
stderr'"

TEST TWO...

The test code outputs "ok!"

[2006-03-14 22:21 UTC] cconstantine at php dot net

Thank you for your bug report. This issue has been fixed
in the latest released version of the package, which you can download at
http://pear.php.net/get/System_Command