executeCommand
codebolt.terminal.executeCommand(command: string, returnEmptyStringOnSuccess: boolean): Promise<CommandFinish | CommandError>
Executes a given command in the terminal environment and returns the result. This method listens for WebSocket messages that indicate the output, error, or finish state of the executed command and resolves the promise accordingly.
Parameters
command(string): The command to be executed in the terminal (e.g., "node --version", "npm install", "ls -la").returnEmptyStringOnSuccess(boolean): Optional parameter to return empty string on success instead of command output. Defaults to false.
Returns
Promise<CommandFinish | CommandError>: A promise that resolves with either a CommandFinish object (on success) or CommandError object (on failure) containing the command's output or error information.
Response Structure
The method returns a Promise that resolves to either a CommandFinish or CommandError object:
CommandFinish (Success Response)
type(string): Always "commandFinish".exitCode(number): The exit code of the command (0 for success).stdout(string, optional): Standard output from the command.stderr(string, optional): Standard error output from the command.success(boolean, optional): Indicates if the operation was successful.message(string, optional): Additional information about the response.data(any, optional): Additional data from the response.messageId(string, optional): Unique identifier for the message.threadId(string, optional): Thread identifier for the request.
CommandError (Error Response)
type(string): Always "commandError".error(string): Error message describing what went wrong.exitCode(number, optional): The exit code of the failed command.stderr(string, optional): Standard error output from the command.success(boolean, optional): Indicates if the operation was successful (typically false).message(string, optional): Additional information about the response.data(any, optional): Additional data from the response.messageId(string, optional): Unique identifier for the message.threadId(string, optional): Thread identifier for the request.
Examples
// Example 1: Basic command execution
const nodeVersionResult = await codebolt.terminal.executeCommand('node --version');
console.log('