protected function handleStream($stream)
    {
        if (!$stream) {
            throw new BuildException("Could not execute command!");
        }

        $this->log("Executing command {$this->command}", Project::MSG_VERBOSE);

        stream_set_blocking($stream, true);
        $result = stream_get_contents($stream);

        // always load contents of error stream, to make sure not one command failed
        $stderr_stream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
        stream_set_blocking($stderr_stream, true);
        $result_error = stream_get_contents($stderr_stream);

        if ($this->display) {
            print($result);
        }

        if (!empty($this->property)) {
            $this->project->setProperty($this->property, $result);
        }

        fclose($stream);
        if (isset($stderr_stream)) {
            fclose($stderr_stream);
        }

        if ($this->failonerror && !empty($result_error)) {
            throw new BuildException("SSH Task failed: " . $result_error);
        }
    }