Another noob question which remained unanswered in the discord user chat, and on which I couldn't really find any specific answer, nor could I manage to answer myself.
I have a child: Child
which is spawned using .spawn()
and I want to stream read both stdout
and stderr
from it using BufReader::new(stdout).lines(..)
.
Creating a BufReader
from child.stdout
moves child
into BufReader
and I can't use it anywhere else after that.
Borrowing with &child.stdout
doesn't work as BufReader
seems to be needing to own the emitter.
I haven't found any examples of using both stdout
and stderr
with a Child
using a streamed reader, only using a single .output
or .wait_with_output
and getting the whole stdout
and stderr
contents at once, which may be quite a large block of text.
Why I want it to work this way - I want to read stdout line by line to parse it for valuable info (upload links of the appcenter
CLI for example) - the main reason. I also want to append the log files with those lines to robustly check for any output of running commands in case of something stops abruptly.
There are really two questions:
- How do I read both
stdout
andstderr
of theChild
and thenwait()
for aChild
to end. - Is it the correct way to approach solving the problem of parsing lines and using log files?