protected function exec($cmd, Result $result)
    {
        //Tmp file to store stderr
        $tempStdErr = tempnam($this->tmpDir, 'cmr');

        if (!$tempStdErr) {
            throw new Exception("Could not create temporary file on $tempStdErr");
        }

        $otp = array();
        $exitCode = null;

        if ($this->stdIn !== null) {
            $filename = $this->createFauxStdIn($this->stdIn);

            if ($this->os->isWindowsLike()) {
                $cat = "type $filename";
            } else {
                $cat = "cat $filename";
            }

            $cmd = "$cat | $cmd";
        }

        //Set CWD
        $prevCwd = getcwd();
        if ($this->cwd) {
            chdir($this->cwd);
        }

        $result->setLastLine(trim(exec("$cmd 2> $tempStdErr", $otp, $exitCode)));

        $result->setStdIn($this->stdIn)
            ->setStdOut(implode(PHP_EOL, $otp))
            ->setStdErr(file_get_contents($tempStdErr))
            ->setExitCode($exitCode);

        // restore CWD
        chdir($prevCwd);

        return $result;
    }
protected function exec($cmd, Result $result)
    {
        //Tmp file to store stderr
        $tempStdErr = tempnam($this->tmpDir, 'cmr');

        if (!$tempStdErr) {
            throw new Exception("Could not create temporary file on $tempStdErr");
        }

        $otp = array();
        $exitCode = null;

        if ($this->stdIn !== null) {
            $filename = $this->createFauxStdIn($this->stdIn);

            if ($this->os->isWindowsLike()) {
                $cat = "type $filename";
            } else {
                $cat = "cat $filename";
            }

            $cmd = "$cat | $cmd";
        }

        //Set CWD
        $prevCwd = getcwd();
        if ($this->cwd) {
            chdir($this->cwd);
        }

        $result->setLastLine(trim(exec("$cmd 2> $tempStdErr", $otp, $exitCode)));

        $result->setStdIn($this->stdIn)
            ->setStdOut(implode(PHP_EOL, $otp))
            ->setStdErr(file_get_contents($tempStdErr))
            ->setExitCode($exitCode);

        // restore CWD
        chdir($prevCwd);

        return $result;
    }
protected function exec ( $ cmd , Result $ result ) { //Tmp file to store stderr $ tempStdErr = tempnam ( $ this -> tmpDir , 'cmr' ) ; if ( ! $ tempStdErr ) { throw new Exception ( "Could not create temporary file on $tempStdErr" ) ; } $ otp = array ( ) ; $ exitCode = null ; if ( $ this -> stdIn !== null ) { $ filename = $ this -> createFauxStdIn ( $ this -> stdIn ) ; if ( $ this -> os -> isWindowsLike ( ) ) { $ cat = "type $filename" ; } else { $ cat = "cat $filename" ; } $ cmd = "$cat | $cmd" ; } //Set CWD $ prevCwd = getcwd ( ) ; if ( $ this -> cwd ) { chdir ( $ this -> cwd ) ; } $ result -> setLastLine ( trim ( exec ( "$cmd 2> $tempStdErr" , $ otp , $ exitCode ) ) ) ; $ result -> setStdIn ( $ this -> stdIn ) -> setStdOut ( implode ( PHP_EOL , $ otp ) ) -> setStdErr ( file_get_contents ( $ tempStdErr ) ) -> setExitCode ( $ exitCode ) ; // restore CWD chdir ( $ prevCwd ) ; return $ result ; }
Method to run the command using exec

@param  string    $cmd    The command string
@param  Result    $result A result object used to store the result of the command
@return Result    The command's result
@throws Exception
Method to run the command using exec