Prose\UsingHost::runCommandAsUser PHP Method

runCommandAsUser() public method

public runCommandAsUser ( $command, $user )
    public function runCommandAsUser($command, $user)
    {
        // what are we doing?
        $log = usingLog()->startAction("run command '{$command}' as user '{$user}' on host '{$this->args[0]}'");
        // make sure we have valid host details
        $hostDetails = $this->getHostDetails();
        // get an object to talk to this host
        $host = OsLib::getHostAdapter($this->st, $hostDetails->osName);
        // make a copy of the hostDetails, so that we can override them
        $myHostDetails = clone $hostDetails;
        $myHostDetails->sshUsername = $user;
        // run the command in the guest operating system
        $result = $host->runCommand($myHostDetails, $command);
        // did the command succeed?
        if ($result->didCommandFail()) {
            $msg = "command failed with return code '{$result->returnCode}' and output '{$result->output}'";
            $log->endAction($msg);
            throw new E5xx_ActionFailed(__METHOD__, $msg);
        }
        // all done
        $log->endAction();
        return $result;
    }