note 18022 deleted from function.system by irchtml
| From: | irchtml@php.net | Date: | Tue, 17 Feb 2004 14:14:41 +0000 |
| Subject: | note 18022 deleted from function.system by irchtml | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-65288@lists.php.net to get a copy of this message | ||
Note Submitter: lowery@craiglowery.com
----
system() is messy in that it returns the last line of the output, and it prints it as well. A
replacement for system which behaves more like the C library system() call by returning the numeric
status code is given below. It is different in that it combines stdout and stderr and only prints
them if $hide is set false:
function mysystem($command, $hide=true) {
if (!($p=popen("($command)2>&1","r"))) return 126;
while (!feof($p)) {
$l=fgets($p,1000);
if (!$hide) print $l;
}
return pclose($p);
}