Skip to content

Instantly share code, notes, and snippets.

@harmo
Last active December 18, 2016 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harmo/14a3553eb2a1ec4751ff to your computer and use it in GitHub Desktop.
Save harmo/14a3553eb2a1ec4751ff to your computer and use it in GitHub Desktop.
<?php
public static function my_exec($cmd, $input = '', $outputFile = ''){
$proc = proc_open($cmd, array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('file', $outputFile, 'w')), $pipes);
fwrite($pipes[0], $input);
fclose($pipes[0]);
$stdout = stream_get_contents($pipes[1]);fclose($pipes[1]);
$rtn = proc_close($proc);
return array(
'stdout'=>$stdout,
'return'=>$rtn
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment