7 class Process
implements IO
16 * Process' stdio pipes
22 * @param string $command
25 * @throws \RuntimeException
27 function __construct($command, $cwd = null, array $env = null) {
28 $this->process
= proc_open($command, [["pipe","r"],["pipe","w"],["pipe","w"]], $this->pipes
, $cwd, $env);
30 if (!is_resource($this->process
) ||
!($status = proc_get_status($this->process
))) {
31 throw new \
RuntimeException("Could not open proc '$command': " . error_get_last()["message"]);
34 stream_set_blocking($this->pipes
[1], false);
35 stream_set_blocking($this->pipes
[2], false);
39 * Cleanup pipes and proc handle
41 function __destruct() {
42 foreach ($this->pipes
as $fd) {
43 if (is_resource($fd)) {
47 proc_close($this->process
);
54 function getOutput() {
55 return $this->pipes
[1];
63 return $this->pipes
[0];
71 function __invoke($fd) {
73 copy($fd, $this->getInput());
75 return $this->getOutput();