stdOut = $tmpStdOut; $this->stdErr = $tmpStdErr; $this->process = new Process($this->command, fds: [ 1 => $this->stdOut, 2 => $this->stdErr, ]); $this->process->start($this->loop); $this->setCallbacks($onData, $onError); $this->process->on('exit', function ($exitCode) use ($onExit): void { $this->cancelTimer(); $output = ''; rewind($this->stdOut); $output .= stream_get_contents($this->stdOut); rewind($this->stdErr); $output .= stream_get_contents($this->stdErr); $onExit($exitCode, $output); fclose($this->stdOut); fclose($this->stdErr); }); } public function quit(): void { $this->cancelTimer(); if (!$this->process->isRunning()) { return; } foreach ($this->process->pipes as $pipe) { $pipe->close(); } $this->endConnection(); } }