Using the Command struct, how can I add a prefix to the stdout and stderr buffers?
I would like the output to look something like this:
[stdout] things are good.
[sterr] fatal: repository does not exist.
This would also be nice to apply to the program's main stdout so anything the program prints is prefixed like that.
Here is the code I currently have:
let output = Command::new("git").arg("clone").output().unwrap_or_else(|e| {
panic!("Failed to run git clone: {}", e)
});
I don't believe you can do what you truly want to do right now. Ideally, you'd be able to provide an implementor of
Write
to theProcess::stdout
method. Unfortunately, the set of choices forStdio
is sparse. Perhaps you can campaign to have this be a feature request for Rust 1.1, or create a crate to start fleshing out some of the details (like cross-platform compatibility)If it is acceptable to remove the interleaving of stdout / stderr, then this solution could help: