Sends arbitrary command
@param  string $cmd Command
@param  string $q Data
@param  callable $cb Optional
@throws ConnectionFinished
@callback $cb ( Connection $conn, boolean $success )
@return boolean            Success
184027
public function command($cmd, $q = '', $cb = null)
    {
        if ($this->phase !== self::PHASE_HANDSHAKED) {
            return false;
        }

        $this->onResponse->push($cb);
        $this->seq = 0;
        $this->sendPacket(chr($cmd) . $q);

        return true;
    }
1346585
public function run(string $cmd, array $acceptableExitCodes = [0]) : Result
    {
        $old            = error_reporting(0);
        $descriptorSpec = [
            ['pipe', 'r'],
            ['pipe', 'w'],
            ['pipe', 'w'],
        ];

        $process = proc_open($cmd, $descriptorSpec, $pipes);
        if (!is_resource($process)) {
            throw new RuntimeException('can\'t execute \'proc_open\'');
        }

        $stdOut = stream_get_contents($pipes[1]);
        fclose($pipes[1]);

        $stdErr = stream_get_contents($pipes[2]);
        fclose($pipes[2]);

        $code = proc_close($process);
        error_reporting($old);

        return new Result($cmd, $code, $stdOut, $stdErr, '', $acceptableExitCodes);
    }
273563
def send (self, command, *args, **kwargs):
        
        status   = False
        cmdobj   = self._cmddict.create(command, *args, **kwargs)
        messages = []

        if not cmdobj.validate(messages):
            for msg in messages:
                log.error(msg)
        else:
            encoded = cmdobj.encode()

            if self._verbose:
                size = len(cmdobj.name)
                pad  = (size - len(cmdobj.name) + 1) * ' '
                gds.hexdump(encoded, preamble=cmdobj.name + ':' + pad)

            try:
                values = (self._host, self._port, str(cmdobj))
                log.command('Sending to %s:%d: %s' % values)
                self._socket.sendto(encoded, (self._host, self._port))
                status = True

                with pcap.open(self.CMD_HIST_FILE, 'a') as output:
                    output.write(str(cmdobj))
            except socket.error as e:
                log.error(e.message)
            except IOError as e:
                log.error(e.message)

        return status
995247
public static function make( $cmd, $params )
	{
		if ( !is_array( $params ) )
		{
			$params = array( $params );
		}
		
		$forge = new static;
		
		if ( !method_exists( $forge, $cmd ) )
		{
			throw new CCException( "CCForge_Php - Command could not be found." );
		}
		
		return call_user_func_array( array( $forge, $cmd ), $params );
	}
1220253
public function sendfile($outfd, $cb, $startCb = null, $offset = 0, $length = null, $pri = EIO_PRI_DEFAULT)
    {
        $cb = CallbackWrapper::forceWrap($cb);
        if (!$this->fd) {
            if ($cb) {
                $cb($this, false);
            }
            return false;
        }
        if (!FileSystem::$supported) {
            if ($cb) {
                $cb($this, false);
            }
            return false;
        }
        static $chunkSize = 1024;
        $ret = true;

        $handler = function (
            $file,
            $sent = -1
        ) use (
            &$ret,
            $outfd,
            $cb,
            &$handler,
            &$offset,
            &$length,
            $pri,
            $chunkSize
        ) {
            if ($outfd instanceof IOStream) {
                if ($outfd->isFreed()) {
                    $cb($file, false);
                    return;
                }
                $ofd = $outfd->getFd();
            } else {
                $ofd = $outfd;
            }
            if (!$ret) {
                $cb($file, false);
                return;
            }
            if ($sent === -1) {
                $sent = 0;
            }
            $offset += $sent;
            $length -= $sent;
            if ($length <= 0) {
                $cb($file, true);
                return;
            }
            if (!$ofd) {
                $cb($file, false);
                return;
            }
            $c = min($chunkSize, $length);
            $ret = eio_sendfile($ofd, $file->fd, $offset, $c, $pri, $handler, $file);
        };
        if ($length !== null) {
            if ($startCb !== null) {
                if (!$startCb($this, $length, $handler)) {
                    $handler($this);
                }
            } else {
                $handler($this);
            }
            return true;
        }
        $this->statRefresh(function ($file, $stat) use ($startCb, $handler, &$length) {
            $length = $stat['size'];
            if ($startCb !== null) {
                if (!$startCb($file, $length, $handler)) {
                    $handler($file);
                }
            } else {
                $handler($file);
            }
        }, $pri);
        return true;
    }
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);
    }
1162999
function(command, callback) {
    var self = this;
    return new Promise(function(resolve, reject) {
        var prCB = function(err, data) {
          if (err) {
            log.error(err.message);
            log.debug(command);
          }
          return (err ? reject('err') : resolve(data));
        };
        self.connection.execute(command, function(err, result) {
          prCB(err, result)
        });
    });
  }
1118237
function interactiveWrite($cmd)
    {
        if (!($this->bitmap & NET_SSH1_MASK_LOGIN)) {
            user_error('Operation disallowed prior to login()', E_USER_NOTICE);
            return false;
        }

        if (!($this->bitmap & NET_SSH1_MASK_SHELL) && !$this->_initShell()) {
            user_error('Unable to initiate an interactive shell session', E_USER_NOTICE);
            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', E_USER_NOTICE);
            return false;
        }

        return true;
    }
264125
def _send_cmd(self, cmd: str):
        """"""
        self._sock.sendall(cmd.encode(encoding='latin-1', errors='strict'))
1119157
def __send_command(self, command, command_string=b'', response_size=8):
        
        if command not in [const.CMD_CONNECT, const.CMD_AUTH] and not self.is_connect:
            raise ZKErrorConnection("instance are not connected.")

        buf = self.__create_header(command, command_string, self.__session_id, self.__reply_id)
        try:
            if self.tcp:
                top = self.__create_tcp_top(buf)
                self.__sock.send(top)
                self.__tcp_data_recv = self.__sock.recv(response_size + 8)
                self.__tcp_length = self.__test_tcp_top(self.__tcp_data_recv)
                if self.__tcp_length == 0:
                    raise ZKNetworkError("TCP packet invalid")
                self.__header = unpack('<4H', self.__tcp_data_recv[8:16])
                self.__data_recv = self.__tcp_data_recv[8:]
            else:
                self.__sock.sendto(buf, self.__address)
                self.__data_recv = self.__sock.recv(response_size)
                self.__header = unpack('<4H', self.__data_recv[:8])
        except Exception as e:
            raise ZKNetworkError(str(e))

        self.__response = self.__header[0]
        self.__reply_id = self.__header[3]
        self.__data = self.__data_recv[8:]
        if self.__response in [const.CMD_ACK_OK, const.CMD_PREPARE_DATA, const.CMD_DATA]:
            return {
                'status': True,
                'code': self.__response
            }
        return {
            'status': False,
            'code': self.__response
        }
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;
    }
970468
protected function writeSocket($cmd, $result = false)
    {
        if (is_null($this->socket)) {
            return false;
        }

        fwrite($this->socket, $cmd . "\r\n");

        if (true == $result) {
            return $this->readSocket();
        }

        return true;
    }
291275
public function sendPing($host, $cb)
    {
        $this->connect('raw://' . $host, function ($conn) use ($cb) {
            $conn->sendEcho($cb);
        });
    }
515598
public function send($command, $data)
    {
        $message = new Message;

        $message->command = $command;
        $message->data = $data;

        $this->connection->send($message->serialize());
    }
306600
function bridgeCommand(command,cb){
    if(!connected) return setImmediate(function(){
      cb('killed');
    });

    if(!connected.pings) connected.pings = {};
    var id = ++pingid;
    var timer;
    connected.pings[id] = function(err,data){
      clearTimeout(timer);
      delete connected.pings[id]
      cb(err,data);
    };
    connected.send({command:command,cb:id});
    // set 5 second time limit for callback.
    timer = setTimeout(function(){
      cb("timeout");
    },5000);
  }
274248
public function connectCommand(Command $cmd)
    {
        $name = $cmd->name();
        $this->commands[$name] = $cmd;

        // regsiter command aliases to the alias table.
        $aliases = $cmd->aliases();
        if (is_string($aliases)) {
            $aliases = preg_split('/\s+/', $aliases);
        }

        if (!is_array($aliases)) {
            throw new InvalidArgumentException('Aliases needs to be an array or a space-separated string.');
        }

        foreach ($aliases as $alias) {
            $this->aliases[$alias] = $cmd;
        }
    }
640364
public function send($cmd)
    {
        // must be connected
        if (!$this->isConnect()) {
            $this->statusManager->setStatus($this->users,new Domain($this->domain),0,'No connection');
            return false;
        }

        $result = false;
        // write the cmd to the connection stream
        try {
            if ($this->validationOptions['debug'] === true) {
                $this->debug[] = ["timestamp" => microtime(true), "message" => "send> {$cmd}"];
            }

            $result = fwrite($this->socket, $cmd . self::CRLF);
        } catch (\Exception $e) {
            // did the send work?
            if ($result === false) {
                $this->statusManager->setStatus($this->users,new Domain($this->domain),0,'Send failed on: '. $this->host );
                return $result;
            }
        }

        return $result;
    }