Weird interaction between Stdio::piped and Child::try_wait

I expect the problem is that the buffer it uses for stdout is filled up and never consumed, so it hangs while waiting for the buffer to be read. In the example you can just use Command::output instead, but I assume your actual use case is more complex.

Try this for example

    let mut stdout = cmd.stdout.take().unwrap();
    let mut buf = [0; 512];
    while cmd.try_wait().unwrap().is_none() {
        stdout.read(&mut buf).unwrap();
    }

edit: There's an open issue regarding this, where you can also find a comment by me from earlier this year when I also bumped into this. :sweat_smile:

2 Likes