Sends a command to the remote host.
@param string $cmd    The cmd to send
@return int|bool      Number of bytes written to the stream
@throws Exception
@throws Exception_Send_Failed
344244
protected function send($cmd)
        {
            // must be connected
            if (!$this->connected()) {
                throw new Exception('No connection');
            }
            $this->debug('send>>>: ' . $cmd);
            // write the cmd to the connection stream
            $result = fwrite($this->socket, $cmd . self::CRLF);
            // did the send work?
            if ($result === false) {
                throw new Exception_Send_Failed('Send failed ' .
                'on: ' . $this->host);
            }
            return $result;
        }
1148200
private function execCmd($cmd, &$stdout = null, &$stderr = null)
    {
        $descriptorspec = array(
            0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
            1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
            2 => array("pipe", "w")   // stderr is a file to write to
        );

        $pipes= array();
        $process = proc_open($cmd, $descriptorspec, $pipes);

        $stdout = "";
        $stderr = "";

        if (!is_resource($process)) {
            return false;
        }

        #close child's input imidiately
        fclose($pipes[0]);

        stream_set_blocking($pipes[1], false);
        stream_set_blocking($pipes[2], false);

        $todo= array($pipes[1],$pipes[2]);

        while (true) {
            $readstdout = [];
            $readstderr = [];

            if (false !== !feof($pipes[1])) {
                $readstdout[]= $pipes[1];
            }

            if (false !== !feof($pipes[2])) {
                $readstderr[]= $pipes[2];
            }

            if (empty($readstdout)) {
                break;
            }

            $write = null;
            $ex = null;
            $ready = stream_select($readstdout, $write, $ex, 2);

            if (false === $ready) {
                // probably dead process
                break;
            }

            foreach ($readstdout as $out) {
                $line = fread($out, 1024);
                $stdout.= $line;
            }

            foreach ($readstderr as $out) {
                $line = fread($out, 1024);
                $stderr.= $line;
            }
        }

        $stdout = strlen($stdout) > 0 ? $stdout : null;
        $stderr = strlen($stderr) > 0 ? $stderr : null;

        fclose($pipes[1]);
        fclose($pipes[2]);

        return proc_close($process);
    }
352126
def send_command(self, cmd):
        
        if not cmd:
            return

        with open(self.fifo, 'wb') as f:
            f.write(cmd)
1343464
public function execute($cmd, $data)
    {
        // Use pipes for STDIN, STDOUT, and STDERR
        $descr = array(
          0 => array(
            'pipe',
            'r'
          ) ,
          1 => array(
            'pipe',
            'w'
          ) ,
          2 => array(
            'pipe',
            'w'
          )
        );
        $pipes = [];

        // Start process, telling it to use STDIN for input and STDOUT for output.
        $cmd = escapeshellcmd($cmd);
        $process = proc_open($cmd, $descr, $pipes);

        // Get the data into pipe only if data is resource
        if (gettype($data) == "resource") {
            // Stream input to STDIN
            while (!feof($data)) {
                fwrite($pipes[0], fread($data, 1024));
            }

            // Close STDIN and the source data.
            fclose($pipes[0]);
            fclose($data);
        }

        // Wait for process to finish while reading STDOUT to a temp stream.
        // Otherwise the process can block indefinitely if STODUT gets bigger
        // than 4kb.
        $this->output = fopen("php://temp", 'w+');
        $exit_code = null;
        while ($exit_code === null) {
            $status = proc_get_status($process);
            if ($status['running'] === false) {
                $exit_code = $status['exitcode'];
            }

            $chunk = stream_get_contents($pipes[1]);
            if ($chunk !== false) {
                fwrite($this->output, $chunk);
            }
        }

        // Close STDOUT
        fclose($pipes[1]);

        // On error, extract message from STDERR and throw an exception.
        if ($exit_code != 0) {
            $msg = stream_get_contents($pipes[2]);
            $this->cleanup($pipes, $this->output, $process);
            if ($this->log) {
                $this->log->error('Process exited with non-zero code.', [
                  'exit_code' => $exit_code,
                  'stderr' => $msg,
                ]);
            }
            throw new \RuntimeException($msg, 500);
        }

        // Return a function that streams the output.
        return function () use ($pipes, $process) {
            rewind($this->output);
            while (!feof($this->output)) {
                echo fread($this->output, 1024);
                ob_flush();
                flush();
            }
            $this->cleanup($pipes, $this->output, $process);
        };
    }
1167373
protected function executeCommand($cmd)
    {
        // Shell-escape all arguments except the command.
        $args = func_get_args();
        foreach ($args as $index => $arg) {
            if ($index !== 0) {
                $args[$index] = escapeshellarg($arg);
            }
        }

        // And replace the arguments.
        $command = call_user_func_array('sprintf', $args);
        $output = '';
        if ($this->io->isVerbose()) {
            $this->io->write('<comment>' . $command . '</comment>');
            $io = $this->io;
            $output = function ($type, $data) use ($io) {
                if ($type === Process::ERR) {
                    $io->write('<error>' . $data . '</error>');
                } else {
                    $io->write('<comment>' . $data . '</comment>');
                }
            };
        }
        return ($this->executor->execute($command, $output) === 0);
    }
437824
protected function sendCommandToServer(string $command): void
	{
		$this->lastCommand = $command;

		$this->connection->write($command);
	}
664992
function interactiveWrite($cmd)
    {
        if (!($this->bitmap & self::MASK_LOGIN)) {
            user_error('Operation disallowed prior to login()');
            return false;
        }

        if (!($this->bitmap & self::MASK_SHELL) && !$this->_initShell()) {
            user_error('Unable to initiate an interactive shell session');
            return false;
        }

        $data = pack('CNa*', NET_SSH1_CMSG_STDIN_DATA, strlen($cmd), $cmd);

        if (!$this->_send_binary_packet($data)) {
            user_error('Error sending SSH_CMSG_STDIN');
            return false;
        }

        return true;
    }
1244780
protected function execCommand(string $cmd, ...$args)
    {
        $command = $this->predis->createCommand($cmd, $args);
        $response = $this->predis->executeCommand($command);

        if ($response instanceof ErrorInterface) {
            return false;
        }

        if ($response instanceof Status) {
            return $response->getPayload() === 'OK';
        }

        return $response;
    }
100518
function send_commands(cmds, cb) {
        function callback(value) {
            if (cb) cb(value)
            this.locked = false
        }
        function run() { 
            if (this.locked = cmds.length > 0) send_command(cmds.shift(), (success) => {
                if (success) setTimeout(run, 200);
                else callback(false);
            });
            else callback(true); 
        };
        if(!this.locked) run();
    }
1367541
protected function instantiateCommand($cmd)
    {
        if (!is_array($cmd)) {
            $cmd = [$cmd];
        }

        if (count($cmd)) {
            if (!is_numeric(current(array_keys($cmd)))) {
                $cmd = [$cmd];
            }
        }

        $command = new Command\SequenceCommand();

        foreach ($cmd as $c) {
            $cc = $this->instantiateSingleCommand($c);
            if ($cc instanceof CommandInterface) {
                $command->add($cc);
            } elseif (null !== $cc) {
                throw new \RuntimeException('Instantiated command is not a valid command', 16);
            }
        }

        return $command;
    }
99967
private function execute($cmd)
    {
        $process = new Process(escapeshellcmd($cmd), $this->projectPath);
        $process->run();
        if (!$process->isSuccessful()) {
            $output = !empty($process->getErrorOutput()) ? $process->getErrorOutput() : $process->getOutput();
            throw new CompassException($output);
        }
        $this->output = $process->getOutput();
    }
49836
function cmd_RETR($fd, $cmd)
    {
        $user = $this->getUser($fd);
        $ftpsock = $this->getUserSock($user);
        if (($file = $this->getFile($user, $cmd[1])) != false)
        {
            $this->send($fd, "150 Connecting to client");
            if ($fp = fopen($file, "r"))
            {
                while (!feof($fp))
                {
                    $cont = fread($fp, 1024);
                    if (!fwrite($ftpsock, $cont)) break;
                }
                if (fclose($fp) and $this->closeUserSock($user))
                {
                    $this->send($fd, "226 File successfully transferred");
                }
                else
                {
                    $this->send($fd, "550 Error during file-transfer");
                }
            }
            else
            {
                $this->send($fd, "550 Can't open " . $cmd[1] . ": Permission denied");
            }
        }
        else
        {
            $this->send($fd, "550 Can't open " . $cmd[1] . ": No such file or directory");
        }
    }
798107
def send_command(self, cmd):
        
        logger.debug('Sending {0} command.'.format(cmd))
        self.comm_chan.sendall(cmd + '\n')
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;
        }
    }
625840
function write($cmd)
    {
        if (!($this->bitmap & NET_SSH2_MASK_LOGIN)) {
            user_error('Operation disallowed prior to login()', E_USER_NOTICE);
            return false;
        }

        if (!($this->bitmap & NET_SSH2_MASK_SHELL) && !$this->_initShell()) {
            user_error('Unable to initiate an interactive shell session', E_USER_NOTICE);
            return false;
        }

        return $this->_send_channel_packet(NET_SSH2_CHANNEL_SHELL, $cmd);
    }
1356319
public function exec($command)
    {
        // Check for prohibited commands
        foreach ($this->prohibitedCommands as $prohibitedCommand) {
            if (strpos(trim($command), $prohibitedCommand) !== false) {
                throw new \Exception('The shell command ' . $command . ' is prohibited');
            }
        }
        return exec($command);
    }
508940
function cmd_PASS($fd, $cmd)
    {
        $user = $this->connections[$fd]['user'];
        $pass = $cmd[1];
        if (isset($this->users[$user]) and $this->users[$user]['password'] == $pass)
        {
            if ($this->users[$user]['chroot'])
            {
                $dir = "/";
            }
            else
            {
                $dir = $this->users[$user]['home'];
            }
            $this->users[$user]['pwd'] = $dir;
            $this->send($fd, "230 OK. Current restricted directory is " . $dir);
            $this->connections[$fd]['login'] = true;
            //send($socket,"230 0 Kbytes used (0%) - authorized: 102400 Kb\r\n");
        }
        else
        {
            $this->send($fd, "530 Login authentication failed");
        }
    }