Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to catch all output and return code? #56

Closed
manfredlotz opened this issue Nov 4, 2023 · 2 comments
Closed

How to catch all output and return code? #56

manfredlotz opened this issue Nov 4, 2023 · 2 comments

Comments

@manfredlotz
Copy link

manfredlotz commented Nov 4, 2023

Assume I run a find command and its output shows found items and also some errors like this

find testdir/
testdir/
testdir/testfile
testdir/fstab
testdir/not_readable
find: ‘testdir/not_readable’: Permission denied

Here I like to catch

  • the found items
  • the errors
  • the return code

How can I do this? Thanks.

@rust-shell-script
Copy link
Owner

rust-shell-script commented Nov 19, 2023

➜  rust_cmd_lib git:(master) ✗ cat examples/catch_all.rs    
use cmd_lib::*;

#[cmd_lib::main]
fn main() -> MainResult {
    let (cmd_res, stdout_res, stderr_res) = spawn_with_output!(ls -d / /xxx)?.wait_with_all();
    info!("cmd err: {}", cmd_res.unwrap_err());
    info!("stdout: {}", stdout_res.unwrap());
    info!("stderr: {}", stderr_res.unwrap());
    Ok(())
}
➜  rust_cmd_lib git:(master) ✗ cargo run --example catch_all
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
     Running `target/debug/examples/catch_all`
[INFO ] cmd err: Running ["ls" "-d" "/" "/xxx"] exited with error; status code: 2
[INFO ] stdout: /
[INFO ] stderr: ls: cannot access '/xxx': No such file or directory

tao-guo added a commit that referenced this issue Nov 19, 2023
Fix #56 and also updated some doc links
@manfredlotz
Copy link
Author

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants