1: <?php
2:
3: namespace WebLoader\Filter;
4:
5: 6: 7: 8: 9: 10:
11: class Process
12: {
13:
14: 15: 16: 17: 18: 19:
20: public static function run($cmd, $stdin = NULL)
21: {
22: $descriptorspec = array(
23: 0 => array('pipe', 'r'),
24: 1 => array('pipe', 'w'),
25: 2 => array('pipe', 'w'),
26: );
27:
28: $pipes = array();
29: $proc = proc_open($cmd, $descriptorspec, $pipes);
30:
31: if (!empty($stdin)) {
32: fwrite($pipes[0], $stdin . PHP_EOL);
33: }
34: fclose($pipes[0]);
35:
36: $stdout = stream_get_contents($pipes[1]);
37: $stderr = stream_get_contents($pipes[2]);
38:
39: $code = proc_close($proc);
40:
41: if ($code != 0) {
42: throw new \RuntimeException($stderr, $code);
43: }
44:
45: return $stdout;
46: }
47:
48: }