note 67183 added to function.shell-exec

From: Date: Mon, 05 Jun 2006 08:45:37 +0000
Subject: note 67183 added to function.shell-exec
Groups: php.notes 
Request: Send a blank email to php-notes+get-113229@lists.php.net to get a copy of this message
For capturing stdout and stderr, when you don't care about the intermediate files, I've had better results with . . . <?php function cmd_exec($cmd, &$stdout, &$stderr) { $outfile = tempnam(".", "cmd"); $errfile = tempnam(".", "cmd"); $descriptorspec = array( 0 => array("pipe", "r"), 1 => array("file", $outfile, "w"), 2 => array("file", $errfile, "w") ); $proc = proc_open($cmd, $descriptorspec, $pipes); if (!is_resource($proc)) return 255; fclose($pipes[0]); //Don't really want to give any input $exit = proc_close($proc); $stdout = file($outfile); $stderr = file($errfile); unlink($outfile); unlink($errfile); return $exit; } ?> This isn't much different than a redirection, except it takes care of the temp files for you (you may need to change the directory from ".") and it blocks automatically due to the proc_close call. This mimics the shell_exec behavior, plus gets you stderr. ---- Server IP: 66.163.161.117 Probable Submitter: 203.162.104.88 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.shell-exec.php Edit -- http://master.php.net/note/edit/67183 Del: integrated -- http://master.php.net/note/delete/67183/integrated Del: useless -- http://master.php.net/note/delete/67183/useless Del: bad code -- http://master.php.net/note/delete/67183/bad+code Del: spam -- http://master.php.net/note/delete/67183/spam Del: non-english -- http://master.php.net/note/delete/67183/non-english Del: in docs -- http://master.php.net/note/delete/67183/in+docs Del: other reasons-- http://master.php.net/note/delete/67183 Reject -- http://master.php.net/note/reject/67183 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#113229) next »