phpseclib\Net\SSH1::exec PHP Method

exec() public method

An SSH1 server will close the connection after a command has been executed on a non-interactive shell. SSH2 servers don't, however, this isn't an SSH2 client. The way this works, on the server, is by initiating a shell with the -s option, as discussed in the following links: {@link http://www.faqs.org/docs/bashman/bashref_65.html http://www.faqs.org/docs/bashman/bashref_65.html} {@link http://www.faqs.org/docs/bashman/bashref_62.html http://www.faqs.org/docs/bashman/bashref_62.html} To execute further commands, a new \phpseclib\Net\SSH1 object will need to be created. Returns false on failure and the output, otherwise.
See also: self::interactiveRead()
See also: self::interactiveWrite()
public exec ( string $cmd, $block = true ) : mixed
$cmd string
return mixed
    function exec($cmd, $block = true)
    {
        if (!($this->bitmap & self::MASK_LOGIN)) {
            throw new \RuntimeException('Operation disallowed prior to login()');
        }
        $data = pack('CNa*', NET_SSH1_CMSG_EXEC_CMD, strlen($cmd), $cmd);
        if (!$this->_send_binary_packet($data)) {
            throw new \RuntimeException('Error sending SSH_CMSG_EXEC_CMD');
        }
        if (!$block) {
            return true;
        }
        $output = '';
        $response = $this->_get_binary_packet();
        if ($response !== false) {
            do {
                $output .= substr($response[self::RESPONSE_DATA], 4);
                $response = $this->_get_binary_packet();
            } while (is_array($response) && $response[self::RESPONSE_TYPE] != NET_SSH1_SMSG_EXITSTATUS);
        }
        $data = pack('C', NET_SSH1_CMSG_EXIT_CONFIRMATION);
        // i don't think it's really all that important if this packet gets sent or not.
        $this->_send_binary_packet($data);
        fclose($this->fsock);
        // reset the execution bitmap - a new \phpseclib\Net\SSH1 object needs to be created.
        $this->bitmap = 0;
        return $output;
    }