Overview
Executes a command on the connected SSH server and returns the output.Method Signature
Parameters
The command to execute on the SSH server.
Optional callback function to handle the result asynchronously.Type Definition:The callback receives:
error: Error object if the operation fails, otherwisenullorundefinedresponse: The command output as a string (only present on success)
Return Value
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