array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the child will write to 2 => array("pipe", "w") // stderr is a pipe that the child will write to ); foreach (explode(';', $commands) as $command){ $parts = explode(" ", $command); $command = escapeshellcmd(realpath($_SERVER['DOCUMENT_ROOT'].array_shift($parts))); if (!$command) continue; $command .= " ".implode(" ", $parts); // should add 'escapeshellarg' here, but this requires changes in all the original arguments $id = mt_rand(); $output = array(); echo "

"; echo ""; echo ""; $proc = proc_open($command." 2>&1", $descriptorspec, $pipes, '/', array()); while ($out = fgets( $pipes[1] )) { $out = preg_replace("%[\t\n\x0B\f\r]+%", '', $out ); @flush(); echo "\n"; @flush(); } $retval = proc_close($proc); echo "\n"; $out = $retval ? "The command failed." : "The command finished successfully!"; echo ""; } } ?>