Executes a command on the Tor server.

@param string $cmd

@throws Exception\IOError
@throws Exception\ProtocolError

@return array
548507
public function executeCommand($cmd)
    {
        $this->checkConnected();

        $write = @fwrite($this->socket, "$cmd\r\n");
        if (false === $write) {
            throw new Exception\IOError('Error while writing to the Tor server');
        }

        $data = [];
        while (true) {
            $response = fread($this->socket, 1024);

            $multiline = false;
            $last_code = null;
            $last_separator = null;
            foreach (explode("\r\n", $response) as $line) {
                $code = substr($line, 0, 3);
                $separator = substr($line, 3, 1);
                $message = substr($line, 4);

                if ('+' === $separator) {
                    $multiline = true;
                    $last_code = $code;
                    $last_separator = $separator;
                }

                if ($multiline) {
                    $data[] = [
                        'code' => $last_code,
                        'separator' => $last_separator,
                        'message' => $line,
                    ];
                } else {
                    if (false === $code || false === $separator) {
                        $e = new Exception\ProtocolError('Bad response format');
                        $e->setResponse($response);

                        throw $e;
                    }

                    if (!in_array($separator, [' ', '+', '-'])) {
                        $e = new Exception\ProtocolError('Unknown separator');
                        $e->setResponse($response);

                        throw $e;
                    }

                    if (!in_array(substr($code, 0, 1), ['2', '6'])) {
                        $e = new Exception\TorError($message, $code);
                        $e->setResponse($response);

                        return $e;
                    }

                    $data[] = [
                        'code' => $code,
                        'separator' => $separator,
                        'message' => $message,
                    ];
                }

                if (' ' === $separator) {
                    break 2;
                }
            }
        }

        return $data;
    }
523479
public function execute($commandContainer)
    {
        $result = array();
        if (is_array($commandContainer)) {
            foreach ($commandContainer as $container) {
                $result = array_merge($result, $this->execute($container));
            }
        }

        if ($commandContainer instanceof CommandContainerInterface) {
            $reflection = new \ReflectionClass($commandContainer);
            $className = $reflection->getShortName();
            $this->logger->info('Execute commands for '.$className.' '.$commandContainer->getName().' ...');

            $commandList = $commandContainer->getCommands();
            foreach ($commandList as $command) {
                $result[] = $this->executeCommand($command, $commandContainer->getPath(), $commandContainer->getOptions());
            }
        }

        return $result;
    }
1158858
static function execute($cmd)
    {
        $result = '';
        echo 'Executing ' . $cmd . PHP_EOL;
        $result = shell_exec($cmd);
        echo($result);
        return $result;
    }
1310231
protected function _exec($cmd, $input = "")
        {
            $result = array(
                'stdout' => '',
                'stderr' => '',
                'return' => ''
            );

            $proc = proc_open(
                $cmd,
                array(
                    0 => array(
                        'pipe',
                        'r'
                    ),
                    1 => array(
                        'pipe',
                        'w'
                    ),
                    2 => array(
                        'pipe',
                        'w'
                    )
                ),
                $pipes
            );
            fwrite($pipes[0], $input);
            fclose($pipes[0]);

            $result['stdout'] = stream_get_contents($pipes[1]);
            fclose($pipes[1]);

            $result['stderr'] = stream_get_contents($pipes[2]);
            fclose($pipes[2]);

            $result['return'] = proc_close($proc);

            return $result;
        }
1243765
public function exec($cmd)
    {
        if (trim($cmd)) {
            $this->setOutputPrefix('');

            if ($this->resolve('DEBUG')) {
                $this->output->writeln('<comment># ' . join('::', Debug::$scope) . "</comment>");
            }

            if ($this->resolve('EXPLAIN')) {
                if ($this->resolve('INTERACTIVE')) {
                    $this->notice('interactive shell:');
                    $line = '( /bin/bash -c \'' . trim($cmd) . '\' )';
                } else {
                    $line = 'echo ' . escapeshellarg(trim($cmd)) . ' | ' . $this->resolve(array('SHELL'));
                }
                $this->output->writeln($line);
            } else {
                $this->executor->execute($cmd);
            }
        }
    }
523757
public function run($cmd, $error = null)
    {
        return $this->helper->run($this->output, $cmd, $error);
    }
1195783
public function runCommand($cmd, $timeout = 120)
    {
        switch ($this->getStage()) {
            case self::ON_DEPLOY:
            case self::ON_RELEASE:
            case self::POST_RELEASE:
                return $this->runRemoteCommand($cmd, true, $timeout);
            default:
                return $this->runLocalCommand($cmd, $timeout);
        }
    }
736431
public static String executeQuery(String[] cmd) throws IOException, InterruptedException {
	return Command.execute(cmd).getOutput();
    }
584392
public function executeCommand(Command $command)
    {
        if ($command instanceof DsnDependent) {
            $command->setDsn($this->dsn);
        }

        $shellCmd = self::VTCTLD_EXECUTABLE . ' ' . $this->getServerString() . ' '
             . $command->getName() . ' ' . implode(' ', $command->getParams());

        exec($shellCmd, $output, $return);
        $output = implode("\n", $output);

        if ($return !== 0) {
            throw new Exception('Error running vtctld command - ' . $shellCmd . ', error: ' . $output);
        }

        $resultClass = $command->getResultClass();

        return new $resultClass($this->dsn, $output);
    }
2522
public function exec($cmd, $args = array())
    {
        // Arguments must be safe
        if (!is_array($args)) {
            $args = array($args);
        }
        foreach ($args as $val) {
            if (!is_string($val)) {
                throw new BaseException('You must specify arguments as strings');
            }
            $this->args[] = escapeshellarg($val);
        }

        // Command myst be safe
        $this->cmd = escapeshellcmd($cmd);

        $this->debug('Executing '.$cmd.($this->args ? ' '.implode(' ', $this->args) : ''));
        // Now do the execution
        $this->executeRaw($this->cmd.' '.implode(' ', $this->args));

        return $this;
    }
578471
public function execute($cmd, $git = true, $cwd = null)
    {
        if ($git) {
            $cmd = $this->getBinaryPath() . ' ' . $cmd;
        }
        $stream = ssh2_exec($this->resource, $cmd);
        stream_set_blocking($stream, 1);
        $data = stream_get_contents($stream);
        fclose($stream);
        // rtrim values
        $values = array_map('rtrim', explode(PHP_EOL, $data));
        $this->outputLines = $values;

        return $this;
    }
824274
public function setCmd(?array $cmd)
    {
        $this->cmd = $cmd;

        $this->raw = array_merge($this->raw, ['Cmd' => $cmd]);

        return $this;
    }
285405
public function execute($command, $cwd = null)
    {
        if (strpos($command, '<') === 0) {
            return array(true, trim($command, '< '));
        }
        
        $processExecutor = $this->getProcessExecutor();

        $logger = $this->logger;

        $output = '';
        
        $outputHandler = function ($type, $data) use ($logger, &$output) {
            $output .= $data;
            
            $logger->writeVerbose('comment', trim($data));
        };
        
        if ($this->logger->getOutputInstance()->isVerbose()) {
            $this->logger->writeIndentation();
        }
        
        $result = $processExecutor->execute($command, $outputHandler, $cwd);

        return array($result === 0, $output);
    }
58357
public static function run($cmd)
    {
        self::initEvn();

        $param = is_array($cmd) && count($cmd) == 2 ? $cmd[1] : $cmd;
        switch ($param) {
            case 'start':
                self::start();
                break;
            case 'stop':
                self::stop();
                break;
            case 'reload':
                self::reload();
                break;
            case 'status':
                self::getStatus(true);
                break;
            case 'add-task':
                if (func_num_args() < 1) {
                    self::message('please input task name');
                    break;
                }
                $args = func_get_args();
                $frequency = isset($args[2]) ? intval($args[2]) : 60;
                self::addTask($args[1], $frequency);
                break;
            case 'rm-task':
                if (func_num_args() < 1) {
                    self::message('please input task name');
                    break;
                }
                $args = func_get_args();
                self::rmTask($args[1]);
                break;
            default:
                self::message('Usage: xxx.php cml.cmd DaemonWorker::run {start|stop|status|addtask|rmtask}');
                break;
        }
    }
283208
public function send($cmd)
    {
        $postVars = [
            'user'       => $this->userName,
            'password'   => $this->key,
            'returncode' => $this->returnCode,
            'cmd'        => $cmd,
        ];
        $args = func_get_args();
        foreach ($args as $num => $arg) {
            if ($num === 0) {
                continue;
            }
            $postVars['arg'.$num] = $args[$num];
        }

        $client = new Client([
            'base_uri'    => 'https://'.$this->host.':8083/api/',
            'timeout'     => 10.0,
            'verify'      => false,
            'form_params' => $postVars,
        ]);

        $query = $client->post('index.php')
            ->getBody()
            ->getContents();

        if ($this->returnCode == 'yes' && $query != 0) {
            throw new VestaExceptions($query);
        }

        return $query;
    }
827984
function execCmd(cmd, allowedErrors = []) {
  debug(`About to execute cmd: ${cmd} with allowed errors: ${JSON.stringify(allowedErrors)}`);
  return exec(cmd, {})
    .then((result) => {
      debug(`Executed successfully cmd: ${cmd}: `, result.stdout);
      const { stdout } = result;
      return stdout;
    })
    .catch((error) => {
      debug(`Executed with error cmd: ${cmd}: `, error.stdout, error.stderr);
      if (allowedErrors.some(allowedError => allowedError.test(error.stderr))) {
        return Promise.resolve(error.stderr);
      }
      return Promise.reject(error);
    });
}
83856
protected static function exec($cmd, $args)
    {
        $command = self::which($cmd) . ' ' . join(' ', array_map('escapeshellarg', $args));
        
        $descriptorspec = array(
           1 => array("pipe", "w"),  // stdout
           2 => array("pipe", "w")   // stderr
        );

        $handle = proc_open($command, $descriptorspec, $pipes);
        if (!$handle) throw new \Exception("Failed to run sox command");
        
        $out = stream_get_contents($pipes[1]);
        $err = stream_get_contents($pipes[2]);
        
        $ret = proc_close($handle);
        if ($ret != 0) throw new \Exception("$cmd command failed. " . trim($err));

        return $out ?: $err;
    }