Replies: 3 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.
-
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.
-
currently also having the same issue described here... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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