src/main/php/Executor.php
public function executeAsync(string $command, string $redirect = '2>&1'): InputStream
    {
        return new class(
                $this->runCommand($command, $redirect),
                $command
        ) extends ResourceInputStream {
            public function __construct($resource, string $command)
            {
                $this->setHandle($resource);
                $this->command = $command;
            }

            public function __destruct()
            {
                try {
                    $this->close();
                } catch (\Exception $e) {
                    // ignore exception
                }
            }

            /**
             * reads given amount of bytes
             *
             * @param   int  $length  optional  max amount of bytes to read
             * @return  string
             * @throws  \LogicException
             * @throws  \stubbles\streams\StreamException
             */
            public function read(int $length = 8192): string
            {
                if (null === $this->handle) {
                    throw new \LogicException('Can not read from closed input stream.');
                }

                $data = @fgets($this->handle, $length);
                if (false === $data) {
                    if (!@feof($this->handle)) {
                        throw new StreamException('Can not read from input stream.');
                    }

                    return '';
                }

                return $data;
            }

            /**
             * closes the stream
             *
             * @throws  \RuntimeException
             */
            public function close()
            {
                if (null === $this->handle) {
                    return;
                }

                $returnCode   = pclose($this->handle);
                $this->handle = null;
                if (0 != $returnCode) {
                    throw new \RuntimeException(
                            'Executing command "' . $this->command . '"'
                            . ' failed: #' . $returnCode
                    );
                }
            }
        };
    }
public function executeAsync(string $command, string $redirect = '2>&1'): InputStream
    {
        return new class(
                $this->runCommand($command, $redirect),
                $command
        ) extends ResourceInputStream {
            public function __construct($resource, string $command)
            {
                $this->setHandle($resource);
                $this->command = $command;
            }

            public function __destruct()
            {
                try {
                    $this->close();
                } catch (\Exception $e) {
                    // ignore exception
                }
            }

            /**
             * reads given amount of bytes
             *
             * @param   int  $length  optional  max amount of bytes to read
             * @return  string
             * @throws  \LogicException
             * @throws  \stubbles\streams\StreamException
             */
            public function read(int $length = 8192): string
            {
                if (null === $this->handle) {
                    throw new \LogicException('Can not read from closed input stream.');
                }

                $data = @fgets($this->handle, $length);
                if (false === $data) {
                    if (!@feof($this->handle)) {
                        throw new StreamException('Can not read from input stream.');
                    }

                    return '';
                }

                return $data;
            }

            /**
             * closes the stream
             *
             * @throws  \RuntimeException
             */
            public function close()
            {
                if (null === $this->handle) {
                    return;
                }

                $returnCode   = pclose($this->handle);
                $this->handle = null;
                if (0 != $returnCode) {
                    throw new \RuntimeException(
                            'Executing command "' . $this->command . '"'
                            . ' failed: #' . $returnCode
                    );
                }
            }
        };
    }
public function executeAsync ( string $ command , string $ redirect = '2>&1' ) : InputStream { return new class ( $ this -> runCommand ( $ command , $ redirect ) , $ command ) extends ResourceInputStream { public function __construct ( $ resource , string $ command ) { $ this -> setHandle ( $ resource ) ; $ this -> command = $ command ; } public function __destruct ( ) { try { $ this -> close ( ) ; } catch ( \ Exception $ e ) { // ignore exception } } /**
             * reads given amount of bytes
             *
             * @param   int  $length  optional  max amount of bytes to read
             * @return  string
             * @throws  \LogicException
             * @throws  \stubbles\streams\StreamException
             */ public function read ( int $ length = 8192 ) : string { if ( null === $ this -> handle ) { throw new \ LogicException ( 'Can not read from closed input stream.' ) ; } $ data = @ fgets ( $ this -> handle , $ length ) ; if ( false === $ data ) { if ( ! @ feof ( $ this -> handle ) ) { throw new StreamException ( 'Can not read from input stream.' ) ; } return '' ; } return $ data ; } /**
             * closes the stream
             *
             * @throws  \RuntimeException
             */ public function close ( ) { if ( null === $ this -> handle ) { return ; } $ returnCode = pclose ( $ this -> handle ) ; $ this -> handle = null ; if ( 0 != $ returnCode ) { throw new \ RuntimeException ( 'Executing command "' . $ this -> command . '"' . ' failed: #' . $ returnCode ) ; } } } ; }
executes given command asynchronous

The method starts the command, and returns an input stream which can be
used to read the output of the command at a later point in time.

@param   string  $command
@param   string  $redirect  optional  how to redirect error output
@return  \stubbles\streams\InputStream
executes given command asynchronous