Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @author Filip Procházka <[email protected]>
- */
- class Process
- {
- /**
- * @return string
- * @throws ProcessException
- */
- public static function execute($cmd)
- {
- $output = NULL;
- $spec = array(
- 0 => 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"), // errors
- );
- if (is_resource($process = proc_open($cmd, $spec, $pipes))) {
- fclose($pipes[0]);
- stream_set_blocking($pipes[1], 1);
- $output = stream_get_contents($pipes[1]);
- fclose($pipes[1]);
- @fclose($pipes[2]);
- if (0 !== proc_close($process)) {
- throw new ProcessException("Error occured while executing: `$cmd`\n\n" . $output);
- }
- } else {
- throw new ProcessException("Could not execute: `$cmd`");
- }
- return $output;
- }
- }
- /**
- * @author Filip Procházka <[email protected]>
- */
- class ProcessException extends \RuntimeException
- {
- }
- $output = Process::execute('plistgenerator.py --url ' . escapeshellarg($url) . ' --path ' . escapeshellarg($_GET['plist']));
Advertisement
Add Comment
Please, Sign In to add comment