Skip to main content

Overview

Executes a command on the connected SSH server and returns the output.

Method Signature

Parameters

string
required
The command to execute on the SSH server.
CallbackFunction<string>
Optional callback function to handle the result asynchronously.Type Definition:
The callback receives:
  • error: Error object if the operation fails, otherwise null or undefined
  • response: The command output as a string (only present on success)

Return Value

Promise<string>
Returns a Promise that resolves with the command output from the server.
  • Resolves: With the response string containing the command output
  • Rejects: With an error if the command execution fails

Usage Example

Notes

  • The command is executed in a non-interactive session
  • Each call to execute() creates a new execution context
  • For interactive shell sessions, use startShell() instead
  • The method returns the combined stdout/stderr output from the command
Last modified on March 26, 2026