diff --git a/src/Communication/StdStreams.php b/src/Communication/StdStreams.php new file mode 100644 index 0000000..cf46b1c --- /dev/null +++ b/src/Communication/StdStreams.php @@ -0,0 +1,82 @@ +stdin === null) { + if (defined("STDIN")) { + $this->stdin = STDIN; + } else { + $this->stdin = fopen("php://stdin", "r"); + } + } + + return $this->stdin; + } + + /** + * @return resource + */ + public function getStdout() + { + if ($this->stdout === null) { + if (defined("STDOUT")) { + $this->stdout = STDOUT; + } else { + $this->stdout = fopen("php://stdout", "w"); + } + } + + return $this->stdout; + } + + /** + * @return resource + */ + public function getStderr() + { + if ($this->stderr === null) { + if (defined("STDERR")) { + $this->stderr = STDERR; + } else { + $this->stderr = fopen("php://stderr", "w"); + } + } + + return $this->stderr; + } +} diff --git a/src/Runtime/RuntimeProcess.php b/src/Runtime/RuntimeProcess.php index 3728081..5f92c93 100644 --- a/src/Runtime/RuntimeProcess.php +++ b/src/Runtime/RuntimeProcess.php @@ -4,6 +4,7 @@ use Aternos\Taskmaster\Communication\Socket\SocketInterface; use Aternos\Taskmaster\Communication\Socket\SocketPair; +use Aternos\Taskmaster\Communication\StdStreams; use Aternos\Taskmaster\TaskmasterOptions; /** @@ -33,15 +34,16 @@ public function __construct(TaskmasterOptions $options, string $runtimeClass) { $socketPair = new SocketPair(); $this->socket = $socketPair->getParentSocket(); + $stdStreams = StdStreams::getInstance(); $this->process = proc_open([ $options->getPhpExecutable(), static::BIN_PATH, $options->getBootstrap(), $runtimeClass ], [ - 0 => STDIN, - 1 => STDOUT, - 2 => STDERR, + 0 => $stdStreams->getStdin(), + 1 => $stdStreams->getStdout(), + 2 => $stdStreams->getStderr(), 3 => $socketPair->getChildSocket()->getStream(), ], $pipes); $socketPair->closeChildSocket(); @@ -83,4 +85,4 @@ public function isRunning(): bool } return proc_get_status($this->process)["running"]; } -} \ No newline at end of file +}