oconnor663 / duct.rs

a Rust library for running child processes
MIT License
795 stars 34 forks source link

wait on process exit but not on output handle closure? #92

Open sunshowers opened 3 years ago

sunshowers commented 3 years ago

Currently, duct's Handle method appears to provide two methods:

  1. wait(), which waits for process exit and for output handles (stdout/stderr) to be closed, and
  2. try_wait(), which checks if the process has exited and:
    • if it hasn't, returns Ok(None)
    • if it has exited, calls wait() and blocks on handles being closed.

I have a use case for a wait() which does not want to wait on handles being closed: specifically, I'm writing a test runner which wants to be able to detect leaked processes and fail a test if the process has exited without handles being closed.

Would it make sense to support that in duct? I'm not exactly sure what a reasonable API for this is. Grandchild handling is so messy on Unix anyway.

oconnor663 commented 3 years ago

I think try_wait shold only block on handles if you've used stdout_capture or similar. So what if instead you opened your own pipes with os_pipe, supplied those via stdout_file or similar, and then used try_wait? Then you could inspect your end of the pipes however you like after you get a return value?