Pantheon\Terminus\Models\Environment::sendCommandViaSsh PHP Method

sendCommandViaSsh() public method

Sends a command to an environment via SSH.
public sendCommandViaSsh ( string $command ) : string[]
$command string The command to be run on the platform
return string[] $response Elements as follow: string output The output from the command run string exit_code The status code returned by the command run
    public function sendCommandViaSsh($command)
    {
        $sftp = $this->sftpConnectionInfo();
        $ssh_command = vsprintf('ssh -T %s@%s -p %s -o "AddressFamily inet" %s', [$sftp['username'], $sftp['host'], $sftp['port'], escapeshellarg($command)]);
        // Catch Terminus running in test mode
        if ($this->getConfig()->get('test_mode')) {
            return ['output' => "Terminus is in test mode. " . "Environment::sendCommandViaSsh commands will not be sent over the wire. " . "SSH Command: {$ssh_command}", 'exit_code' => 0];
        }
        ob_start();
        passthru($ssh_command, $exit_code);
        $response = ['output' => ob_get_clean(), 'exit_code' => $exit_code];
        return $response;
    }