pub fn get_exitcode_stdout_stderr(cmd: &str) -> Option<ProcStat>Expand description
Executes an external command and gets its exit code, stdout and stderr.
It waits for the command to complete.
The three values are returned in a ProcStat structure.
The command must be a simple command with some optional arguments. Pipes, redirections are not allowed.
§Examples
let commands = vec![
r#"python -c "print('Hello Rust!')""#,
"python --version",
];
for cmd in commands.iter() {
let stat = jabba_lib::jprocess::get_exitcode_stdout_stderr(cmd).unwrap();
println!("{:?}", stat);
}
let answer = jabba_lib::jprocess::get_exitcode_stdout_stderr("rustc --version")
.unwrap()
.trimmed_output(); // no trailing whitespaces
println!("{:?}", answer);§Sample Output
ProcStat { exit_code: 0, stdout: "Hello Rust!\n", stderr: "" }
ProcStat { exit_code: 0, stdout: "Python 3.10.5\n", stderr: "" }
"rustc 1.62.1 (e092d0b6b 2022-07-16)"Examples found in repository?
examples/process.rs (line 11)
3fn main() {
4 let commands = vec![
5 r#"python -c "print('Hello Py3!')""#,
6 "python --version",
7 "date",
8 ];
9
10 for cmd in commands.iter() {
11 let stat = jabba_lib::jprocess::get_exitcode_stdout_stderr(cmd).unwrap();
12 println!("{:?}", stat);
13 }
14
15 let date = jabba_lib::jprocess::get_exitcode_stdout_stderr("date")
16 .unwrap()
17 .trimmed_output();
18 println!("{:?}", date);
19
20 let cmd = "ls -al";
21 jproc::exec_cmd(cmd);
22}