Skip to main content

execute_shell_command

Function execute_shell_command 

Source
pub async fn execute_shell_command(
    command: &str,
    working_dir: &Path,
) -> Result<CommandOutput>
Expand description

Executes an arbitrary shell command in a specified working directory.

This function uses the platform’s default shell (sh -c on Unix, cmd /C on Windows). It captures stdout, stderr, and the exit status.

Warning: This function executes arbitrary commands as provided. It does not perform any sandboxing, validation, or user confirmation. Callers must ensure the command is safe to execute or implement appropriate safety measures (like user confirmation) before calling this function. Consider using more specific tool functions (e.g., execute_git_command) where possible.

§Arguments

  • command: The command string to execute via the shell.
  • working_dir: The directory in which to execute the command.

§Returns

A Result containing a CommandOutput struct with the status, stdout, and stderr, or an error if the process failed to spawn.