Skip to content

Instantly share code, notes, and snippets.

@kemadz
Created July 9, 2013 01:55
Show Gist options
  • Save kemadz/5954063 to your computer and use it in GitHub Desktop.
Save kemadz/5954063 to your computer and use it in GitHub Desktop.
<?php
$cmd = 'date';
$desc = array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
2 => array('pipe', 'w')
);
$pwd = '~';
$env = array();
$proc = @proc_open($cmd, $desc, $pipes, $pwd, $env);
if ( is_resource($proc)) {
#fwrite($pipes[0], 'stdin');
fclose($pipes[0]);
$p1 = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$p2 = stream_get_contents($pipes[2]);
fclose($pipes[2]);
proc_close($proc);
print 'stdout: ' . $p1;
print 'stderr: ' . $p2 . "\n";
} else {
print "error.";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment