oconnor663 / shared_child.rs

a wrapper around std::process::Child that lets multiple threads wait or kill at once
MIT License
39 stars 7 forks source link

Provide wait_with_output method #22

Open mcandre opened 1 year ago

mcandre commented 1 year ago

Please provide a convenient wait_with_output method, that works like the basic process::Child's wait_with_output method, so that users can query both the exit status code and the stdout/stderr streams.

oconnor663 commented 1 year ago

Have you considered calling .into_inner().wait_with_output(). Any chance that would work for your use case?

It's been a while since I've thought about this, so I might get some details wrong (or maybe I always had them wrong), but implementing wait_with_output directly on SharedChild is complicated. Of course we could do the equivalent of the into_inner approach above, but presumably the reason you're using SharedChild in the first place is you need to work through shared references. Implementing wait_with_output with a shared reference probably isn't possible. We can't call the underlying method on Child, because we don't have self by value. But we also can't access the underlying stdin/stdout/stderr pipes, because those are private. (We'd also have to clone all the output every time you call the method, since now you can call it more than once. That's easy, but ugly.)

If calling into_inner "at the end" isn't viable for you, I think your next best option might be to use os_pipe to explicitly create pipes that you can pass to the child. Then you can manage ownership of the parent's end of those pipes separately, during the time when the child is shared. Does that make sense?

oconnor663 commented 1 year ago

Oh, os_pipe probably isn't necessary, because you can call .take_stdin() etc.