title: Reading from a processes stdout without placing it all in memory at once
body: <p>I am trying to capture the output from an external tool which is run in a separate process. I would like to do so in a non-blocking way as the output is larger than memory. I saw <a href="https://stackoverflow.com/questions/26550962/how-would-you-stream-output-from-a-process-in-rust">How would you stream output from a Process in Rust?</a> but I am not sure how to proceed. I have copied an example from <a href="http://rustbyexample.com/std_misc/process/pipe.html" rel="nofollow noreferrer">here</a> but this seems to capture output into a variable before proceeding. So far I have:</p>
  
  <pre><code>let path = "/Documents/Ruststuff/DB30_igh_badPE.bam";
  let output = Command::new("samtools")
      .arg("view")
      .arg("-H")
      .arg(path)
      .stdin(Stdio::piped())
      .stdout(Stdio::piped())
      .spawn()
      .unwrap_or_else(|e| panic!("failed {}", e));
  
  let mut s = String::new();
  match output.stdout.unwrap().read_to_string(&amp;mut s) {
      Err(why) =&gt; panic!("{}", Error::description(&amp;why)),
      Ok(_) =&gt; print!("{}", s),
  }
  </code></pre>
  
  <p>Is it possible to loop over <code>stdout</code> from the child process instead of using the match? Something like:</p>
  
  <pre><code>for line in &amp;output.stdout {}
  </code></pre>