-
Notifications
You must be signed in to change notification settings - Fork 34
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
BufReader.lines
over duct::cmd().reader()
never exits if process exited with non-0
#112
Comments
duct::cmd().reader()
never exists if process exited with non-0BufReader.lines
over duct::cmd().reader()
never exits if process exited with non-0
I would argue that this is mostly a feature :) As you've commented, the item type of the I could see an argument that it might be nicer for Does that sound right? |
that is basically what i am doing now (before it was just a
yes it makes it clearer now
how does i dont know for how duct will handle this issue, but i think other people will run into it so to have this issue is good for problem searching. i also reported this because the std Command implementation did not infinitely loop and though this was a problem |
The biggest difference is that For both of those reasons, iterating over use std::io::prelude::*;
use std::io::BufReader;
use std::os::fd::AsRawFd;
use std::process::Stdio;
fn main() {
let child = std::process::Command::new("sh")
.args(["-c", "exit 1"])
.stdout(Stdio::piped())
.spawn()
.unwrap();
// Reach in and close the read end of the child's stdout pipe. This will cause all the reads in
// the loop below to return errors.
unsafe {
libc::close(child.stdout.as_ref().unwrap().as_raw_fd());
}
let stdout_reader = BufReader::new(child.stdout.expect("test stdout"));
for v in stdout_reader.lines() {
println!("LINE {:#?}", v);
}
} |
I have noticed that with duct, if the output is read via a
ReaderHandler
and wrapped in aBufReader
for the.lines()
iterator, it never exits when the underlying process exits with a non-0 exit codereproduction code:
whereas commands spawned with
std::process::Command
end the iteratorduct 0.13.6
rust 1.70.0
Linux
The text was updated successfully, but these errors were encountered: