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

should we make clear std::process::ChildStdout is non-blocking or not? #39810

Closed
hicqu opened this issue Feb 14, 2017 · 4 comments
Closed

should we make clear std::process::ChildStdout is non-blocking or not? #39810

hicqu opened this issue Feb 14, 2017 · 4 comments

Comments

@hicqu
Copy link

hicqu commented Feb 14, 2017

I'm working with std::process::Child::try_wait and std::process::ChildStdout. Here is an example,

let mut child = cmd.spawn().unwrap();
loop {
    let mut buf = [0 as u8; 4096];
    if let Some(ref stream) = child.stdout {
        stream.read(&mut buf).unwrap();           // Will it block?
    }
    match child.try_wait() {
        // something here ...
    }
}

I could not find stream.read(&mut buf) would block or not in API document. I test that simple code on Linux and it didn't blocking. So,

  1. On other platforms, will it block or not?
  2. Should we make clear that for every platform?
  3. Or it's just an undefined behavor, we should set that stream blocking or nonblocking explicitly?

Please help me. Thanks very much!

@alexcrichton
Copy link
Member

Yes on all platforms all I/O in libstd is blocking by default, if not it's a bug!

@hicqu
Copy link
Author

hicqu commented Feb 15, 2017

This means that we should make it clear that std::process:ChildStdout.read is nonblocking in documents, right?

Thank you for continually improving this amazing language!

@alexcrichton
Copy link
Member

Did you mean blocking as opposed to nonblocking? If so, indeed!

@hicqu
Copy link
Author

hicqu commented Feb 15, 2017

Ok, you are right, it's blocking but not nonblocking. Thank you!

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