abu_agent/toolbox/tools/
bash.rs1use std::process::Command;
2
3#[abu_macros::tool(
4 struct_name = Bash,
5 description = "Run a shell command.",
6)]
7pub fn bash(command: &str) -> String {
8 match Command::new("sh")
9 .arg("-c")
10 .arg(command)
11 .output() {
12 Ok(output) => {
13 if output.status.success() {
14 format!("Execute command with stdout: {}", String::from_utf8_lossy(&output.stdout).to_string())
15 } else {
16 format!("Execute command with stderr: {}", String::from_utf8_lossy(&output.stderr).to_string())
17 }
18 }
19 Err(err) => {
20 format!("Failed to execute command because of {}", err.to_string())
21 }
22 }
23}