Replies: 2 comments 3 replies
-
I was able to accomplish my goal by copying Child::wait_with_output() into my code and modifying it to take &mut child instead of self. This makes me believe it is a mistake for that method to take |
Beta Was this translation helpful? Give feedback.
3 replies
-
In theory it should be possible to use Child::wait() and read the process's output. I tried that initially and did not find a good solution. Perhaps someone here can demonstrate how to do it...? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The docs for
tokio::process::Child::kill()
give a simple example how to kill a child process using aselect!()
. The example usesChild::wait()
andChild::kill()
in the two select branches. Theklll()
only occurs if a message is received over a channel.In my case, I need to read
stdout
from the child process. So I'm usingChild::wait_with_output()
. However this method takesself
and thus theselect!()
won't compile.here's a playground.
So, how to do it?
to be clear: happy path is that the child process completes normally and we read its output from stdout. But I also need to support the path that we receive a message while child process is executing and then kill the child process.
I am aware of
Command::kill_on_drop(true)
, which can kill the child process in the background without need for a select!(). That is not a good solution in this case because the application must be certain that the child process has been terminated before proceeding and termnation may take some seconds.kill_on_drop()
docs recommend usingChild::kill()
for such situations.also, I am wondering if
Child::wait_with_output()
really has to takeself
or maybe it should take&mut self
, asChild::wait()
does.Beta Was this translation helpful? Give feedback.
All reactions