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 upNo way to print intermediate Command results #30098
Comments
Gankro
added
A-libs
P-low
labels
Nov 28, 2015
This comment has been minimized.
This comment has been minimized.
|
It's not impossible with the current API, just kind of inconvenient. Given a piped stdout, you can do whatever you want with the stream (including implementing a tee-like mechanism). (Did you mean to file this against rust-lang/rfcs?) |
This comment has been minimized.
This comment has been minimized.
|
(I'm always terrible at picking the right repo) |
This comment has been minimized.
This comment has been minimized.
|
@eefriedman can you elaborate on what you're proposing (I'm not super familiar with piping processes)? |
This comment has been minimized.
This comment has been minimized.
fn main() {
use std::process::Command;
use std::process::Stdio;
use std::io::Read;
use std::io::Write;
use std::io::stdout;
let child = Command::new("cat")
.arg("/usr/include/stdio.h")
.stdout(Stdio::piped())
.spawn()
.unwrap_or_else(|e| { panic!("failed to execute process: {}", e) });
let mut out = child.stdout.unwrap();
let mut read_buf = [0u8; 64];
let mut out_buf: Vec<u8> = Vec::new();
while let Ok(size) = out.read(&mut read_buf) {
if size == 0 {
break;
}
stdout().write_all(&read_buf).unwrap();
out_buf.extend(read_buf.iter());
}
}This writes the child's stdout to the parent's stdout, and saves the result. It could easily be packaged up into a crate if someone was interested. |
This comment has been minimized.
This comment has been minimized.
|
Hey awesome, thanks! I think this is sufficient for the job. |
Gankro
closed this
Nov 29, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gankro commentedNov 28, 2015
I have an application that spends about 30 minutes executing benchmarks by invoking Cargo through std::process::Command. It would be really nice to be able to print intermediate results as each bench completes, but Command doesn't seem to expose anything. It would be sufficient for my purposes to be able to tee stdout/err to the parent process' stdout/err, but a more general mechanism may be desirable.