Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd "Process child process output continuously" example #373
Conversation
budziq
requested changes
Nov 28, 2017
|
Thanks @ludwigpacifici ! Some suggestions below |
| println!("{}", line); | ||
| } | ||
| } | ||
| # |
This comment has been minimized.
This comment has been minimized.
budziq
Nov 28, 2017
Collaborator
the Ok(()) might be a boilerplate but lets not hide it as it is necessary to compile the example when copy pasted
| @@ -12,6 +12,7 @@ | |||
| | [Run an external command passing it stdin and check for an error code][ex-parse-subprocess-input] | [![regex-badge]][regex] | [![cat-os-badge]][cat-os] [![cat-text-processing-badge]][cat-text-processing] | | |||
| | [Run piped external commands][ex-run-piped-external-commands] | [![std-badge]][std] | [![cat-os-badge]][cat-os] | | |||
| | [Redirect both stdout and stderr of child process to the same file][ex-redirect-stdout-stderr-same-file] | [![std-badge]][std] | [![cat-os-badge]][cat-os] | | |||
| | [Continuously process child process' outputs][ex-continuous-process-output] | [![std-badge]][std] | [![cat-os-badge]][cat-os] | | |||
This comment has been minimized.
This comment has been minimized.
budziq
Nov 28, 2017
Collaborator
hmm text-processing badge might make sense. What are your thoughts @ludwigpacifici ?
This comment has been minimized.
This comment has been minimized.
ludwigpacifici
Nov 29, 2017
Author
Contributor
Yep. Plus it will be homogeneous with similar recipes like Run an external command and process stdout.
| let reader = BufReader::new(stdout); | ||
| for line in reader.lines() { |
This comment has been minimized.
This comment has been minimized.
budziq
Nov 28, 2017
Collaborator
how about we try to express this in a functional style with filter_map filter and for_each?
| # extern crate error_chain; | ||
| # | ||
| use std::process::{Command, Stdio}; | ||
| use std::io::BufReader; |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ludwigpacifici
Nov 29, 2017
Author
Contributor
hmm, I remember rustfmt was doing this for me before. But not now. Anyway, let's group them.
| stdout](#ex-parse-subprocess-output), while an external [`Command`] is | ||
| running, process its standard output. A new pipe is created by | ||
| [`Stdio::piped`] and it is read by a [`BufReader`]. Note, a buffered | ||
| reader uses a buffer to reduce the number of I/O requests. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ludwigpacifici
Nov 28, 2017
Author
Contributor
True, it's slightly off topic. While I was implementing the example, I ask myself the question std::io::BufReader vs std::io::Reader. I will remove it. Plus the BufReader link to the doc explains it:
It can be excessively inefficient to work directly with a Read instance. For example, every call to read on TcpStream results in a system call. A BufReader performs large, infrequent reads on the underlying Read and maintains an in-memory buffer of the results.
|
|
||
| Contrary to [Run an external command and process | ||
| stdout](#ex-parse-subprocess-output), while an external [`Command`] is | ||
| running, process its standard output. A new pipe is created by |
This comment has been minimized.
This comment has been minimized.
budziq
Nov 28, 2017
Collaborator
the explanation is slightly unclear. I'd emphasize that the we do not wait for the child process to finish and process the output continuously.
ludwigpacifici commentedNov 27, 2017
fixes #339
Hello @budziq ! Another PR :-) I also added a commit to update the std badge version.