MCPcopy Create free account
hub / github.com/Roy3838/Observer / run_command

Function run_command

cli/src/runner.rs:31–62  ·  view source on GitHub ↗

Run a command with inherited stdio and return the result

(args: &[String])

Source from the content-addressed store, hash-verified

29
30/// Run a command with inherited stdio and return the result
31pub fn run_command(args: &[String]) -> std::io::Result<CommandResult> {
32 if args.is_empty() {
33 return Err(std::io::Error::new(
34 std::io::ErrorKind::InvalidInput,
35 "No command provided",
36 ));
37 }
38
39 let start = Instant::now();
40
41 // First arg is the program, rest are arguments
42 let mut cmd = Command::new(&args[0]);
43 if args.len() > 1 {
44 cmd.args(&args[1..]);
45 }
46
47 // Inherit stdio so the command behaves normally
48 cmd.stdin(Stdio::inherit())
49 .stdout(Stdio::inherit())
50 .stderr(Stdio::inherit());
51
52 // Run and wait
53 let status: ExitStatus = cmd.spawn()?.wait()?;
54
55 let duration = start.elapsed();
56
57 Ok(CommandResult {
58 exit_code: status.code(),
59 duration,
60 success: status.success(),
61 })
62}

Callers 1

mainFunction · 0.85

Calls 1

nowFunction · 0.85

Tested by

no test coverage detected