-
Notifications
You must be signed in to change notification settings - Fork 13.3k
std::process::Command output() method error handling hazards #73126
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
Comments
Another option would be to add a method to the I was one of the people who commented on the pre-RFC thread, and while I don't think the default for Also, in the specific case of |
I think this is a good idea.
My example is an example of code that is wrong precisely because it doesn't check the exit status, but which compiles without warnings. Ie, it demonstrates the hazard that I am complaining about in this issue. |
I've edited things to make this clearer. |
Just came across this and wanted to mention that there are some programs that return non-zero exit codes in some success scenarios like this: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy#exit-return-codes It might be good to consider an addition to this where success or failure exit codes can be specified. |
See RFC: rust-lang/rfcs#3362 |
Closing this as it is blocked on a rfc which seems to be stalled, so better to close this and wait and see if the rfc gets accepted and then have a tracking issue out of it |
Hi. Normally, Rust makes it difficult to accidentally write buggy code. This is one of its great strengths. However, the API of
output()
onstd::process::Command
API has two serious error handling hazards:See the example below.
I think this is very difficult to fix with the current return value from
output()
. It seems to me that there should be a new function whose behaviour is as follows:.stderr(...)
when building theCommand
, any nonempty stderr is treated as an error, giving anErr
return value (whoseDebug
impl prints the stderr output).Err
return value,Debug
impl displays both).I don't know what this should be called. Unfortunately the name
output
has been taken for the more hazardous, raw, function. Which we must retain because if you want to run a command that sometimes succeeds returning nonzero (eg,diff
) you need something like it.(See also #70186 which is about the return value from
spawn()
. I am about to file another issue about the return value fromwait()
)(Playground)
Actual output:
Expected output:
Some kind of compiler warning. Or something in the docs to say not to use
.output()
(and, therefore, something convenient to use instead).The text was updated successfully, but these errors were encountered: