How do I capture stderr output from duct command when duct command throws an error?

Rust playground example

I would like to read the stderr output when the program crashes,
not just see a status number, so I'll know why I'm getting an error.

On my own code with different commands I'm getting on errors like:

command ["sudo", "--", "sh", "-c", "install -m755 -C /usr/bin/qemu-aarch64-static /var/tmp/eqstalxr-bastij/root/usr/bin/qemu-aarch64-static"] exited with code 1

That's not a useful error to me.
I didn't used to have this with std::process::Command But that had it's own issues.

And another issue.
How come duct is not counted as a somewhat popular crate?
It should stand as the #1450th-1500th most popular crate,
well within rustexplorer's 10k crates support.

I don't expect the rust playground to work with this slightly obscure crate, but I do expect it with rust explorer.

https://www.rustexplorer.com/b/c9ag3f

You haven't shown code and I don't know how someone could help with just the error message you've posted.

I have shown code.
It was at the end in rust explorer.
I've now put the same code in the rust playground.
I cannot run the code in the playground because the crate is not supported.
That's why I have no error as of yet that aligns with the playground code.

Sorry, I misunderstood.

I had not noticed this method

Adding unchecked to the run method, then doing
a match command_result.status.success() and catching the std_err like this..

String::from_utf8(command_result.stderr).map_err(|non_utf8| 
String::from_utf8_lossy(non_utf8.as_bytes()).into_owned()).unwrap());

..does the trick

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.