|
5 | 5 | use Evenement\EventEmitter; |
6 | 6 | use React\EventLoop\LoopInterface; |
7 | 7 | use React\Stream\ReadableResourceStream; |
| 8 | +use React\Stream\ReadableStreamInterface; |
8 | 9 | use React\Stream\WritableResourceStream; |
| 10 | +use React\Stream\WritableStreamInterface; |
9 | 11 |
|
10 | 12 | /** |
11 | 13 | * Process component. |
|
17 | 19 | */ |
18 | 20 | class Process extends EventEmitter |
19 | 21 | { |
| 22 | + /** |
| 23 | + * @var ?WritableStreamInterface |
| 24 | + */ |
20 | 25 | public $stdin; |
| 26 | + |
| 27 | + /** |
| 28 | + * @var ?ReadableStreamInterface |
| 29 | + */ |
21 | 30 | public $stdout; |
| 31 | + |
| 32 | + /** |
| 33 | + * @var ?ReadableStreamInterface |
| 34 | + */ |
22 | 35 | public $stderr; |
23 | 36 |
|
| 37 | + /** |
| 38 | + * Array with all process pipes (once started) |
| 39 | + * - 0: STDIN (`WritableStreamInterface`) |
| 40 | + * - 1: STDOUT (`ReadableStreamInterface`) |
| 41 | + * - 2: STDERR (`ReadableStreamInterface`) |
| 42 | + * |
| 43 | + * @var ReadableStreamInterface|WritableStreamInterface |
| 44 | + */ |
| 45 | + public $pipes = array(); |
| 46 | + |
24 | 47 | private $cmd; |
25 | 48 | private $cwd; |
26 | 49 | private $env; |
27 | 50 | private $enhanceSigchildCompatibility; |
28 | 51 | private $sigchildPipe; |
29 | | - private $pipes; |
30 | 52 |
|
31 | 53 | private $process; |
32 | 54 | private $status; |
@@ -99,7 +121,7 @@ public function start(LoopInterface $loop, $interval = 0.1) |
99 | 121 | $cmd = sprintf('(%s) ' . $sigchild . '>/dev/null; code=$?; echo $code >&' . $sigchild . '; exit $code', $cmd); |
100 | 122 | } |
101 | 123 |
|
102 | | - $this->process = proc_open($cmd, $fdSpec, $this->pipes, $this->cwd, $this->env); |
| 124 | + $this->process = proc_open($cmd, $fdSpec, $pipes, $this->cwd, $this->env); |
103 | 125 |
|
104 | 126 | if (!is_resource($this->process)) { |
105 | 127 | throw new \RuntimeException('Unable to launch a new process.'); |
@@ -133,15 +155,23 @@ public function start(LoopInterface $loop, $interval = 0.1) |
133 | 155 | }; |
134 | 156 |
|
135 | 157 | if ($sigchild !== null) { |
136 | | - $this->sigchildPipe = $this->pipes[$sigchild]; |
137 | | - unset($this->pipes[$sigchild]); |
| 158 | + $this->sigchildPipe = $pipes[$sigchild]; |
| 159 | + unset($pipes[$sigchild]); |
| 160 | + } |
| 161 | + |
| 162 | + foreach ($pipes as $n => $fd) { |
| 163 | + if ($n === 0) { |
| 164 | + $stream = new WritableResourceStream($fd, $loop); |
| 165 | + } else { |
| 166 | + $stream = new ReadableResourceStream($fd, $loop); |
| 167 | + $stream->on('close', $streamCloseHandler); |
| 168 | + } |
| 169 | + $this->pipes[$n] = $stream; |
138 | 170 | } |
139 | 171 |
|
140 | | - $this->stdin = new WritableResourceStream($this->pipes[0], $loop); |
141 | | - $this->stdout = new ReadableResourceStream($this->pipes[1], $loop); |
142 | | - $this->stdout->on('close', $streamCloseHandler); |
143 | | - $this->stderr = new ReadableResourceStream($this->pipes[2], $loop); |
144 | | - $this->stderr->on('close', $streamCloseHandler); |
| 172 | + $this->stdin = $this->pipes[0]; |
| 173 | + $this->stdout = $this->pipes[1]; |
| 174 | + $this->stderr = $this->pipes[2]; |
145 | 175 | } |
146 | 176 |
|
147 | 177 | /** |
|
0 commit comments