How can I implement STDOUT read timeout

Hi, I'm trying to implement timeout of reading STDOUT of a Popen process. I have code like that:

// self.process is a subprocess::Popen
self.process
    .stdin
    .as_ref()
    .unwrap()
    .write("Long text".as_bytes());
self.process.stdin.as_ref().unwrap().write("\n".as_bytes());
let mut contents = String::new();
let mut buf_reader =
    BufReader::with_capacity(512 * 1024, self.process.stdout.as_ref().unwrap());
buf_reader.read_line(&mut contents); // Sometime my code hangs here.

I found timeout-readwrite but it doesn't work with Rust 2018.
Could you give me a few advices how can I do a timeout for Read here?

What makes you think it doesn't work with Rust 2018? The very purpose of the edition system is to allow improving the syntax without splitting the library echosystem. You can call the Rust2015 libraries using Rust2018 syntax and vice versa.

Because it doesn't compile even its own examples.

Well you can't mix two syntaxes within a single crate. What was the error?

Few updates:
On Windows I can't run an example with an error

    error[E0432]: unresolved import `timeout_readwrite::TimeoutReadExt`
     --> examples\process.rs:9:5
      |
    9 | use timeout_readwrite::TimeoutReadExt;
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `TimeoutReadExt` in the root

But on Linux it works. On Windows rustc 1.51.0 on linux rustc 1.48.0

Oh the crate doesn't seems to support the windows.

And sorry, I don't have any prior experience about the windows.

1 Like

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.