Possible improvements to System_Command
| From: | Alex Hayes | Date: | Fri, 22 Apr 2005 04:20:27 +0000 |
| Subject: | Possible improvements to System_Command | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-37330@lists.php.net to get a copy of this message | ||
Hello
If these have already been mentioned please disregard, however after
searching the list i couldn't find it.
I have a couple of possible improvements that I think allow better
operation of System_Command
For example, there is no way of obtaining the error that was written to
standard error, it just states that there was something written to
standard error (a little annoying really). From looking at the code it
looks like the intention was there to grab standard error and use it, but
it doesn't get used for anything, unless Im missing something somewhere???
This code appears around line 387:
$error = implode('', file($tmpFile));
$return = PEAR::raiseError(null, SYSTEM_COMMAND_STDERR, null,
E_USER_WARNING, null, 'System_Command_Error', true);
I think that this could be changed to:
$error = implode('', file($tmpFile));
$return = PEAR::raiseError(null, SYSTEM_COMMAND_STDERR, null,
E_USER_WARNING, $error, 'System_Command_Error', true);
You will note that the user_info is being set to the $error, which to my
understanding wouldn't break any backwards compatibility, it would just
mean that we can properly determine what went wrong.
Also this is a nice to have, but, I have come across an annoying behavior
which is not a problem of System_Command but can be rectified with
addition of some changes to System_Command.
For example: when using sendmail (say /usr/sbin/sendmail) from the command
line it does not send errors back to standard error, it sends them back to
standard output. This means that when System_Command catches the 'errors'
there are not any there. So to overcome this I suggest the following
(within the same block of code).
$error = implode('', file($tmpFile));
if(empty($error) && !empty($result)) {
$error = implode('', $result);
}
$return = PEAR::raiseError(null, SYSTEM_COMMAND_STDERR, null,
E_USER_WARNING, $error, 'System_Command_Error', true);
This is obviously not a problem with System_Command, and I believe from
crawling google that newer versions of sendmail will rectify this issue,
however I, and I'm sure many others, are not in a position to install the
most recent version of sendmail, and I'm sure that this problem occurs in
other programs also.
Thanks
Alex