Skip to content

Instantly share code, notes, and snippets.

@itsfarseen
Created September 5, 2019 18:03
Show Gist options
  • Save itsfarseen/dc1089e641ecda015c1963f569a1609b to your computer and use it in GitHub Desktop.
Save itsfarseen/dc1089e641ecda015c1963f569a1609b to your computer and use it in GitHub Desktop.
use std::io::Read;
use std::process;
fn main() {
let cmdline_args: Vec<String> = std::env::args().collect();
let mut path = std::path::Path::new(&cmdline_args[1]).to_path_buf();
let args = &cmdline_args[2..];
let mut proc = process::Command::new(&path)
.args(args)
.stdout(process::Stdio::piped())
.spawn()
.unwrap();
let mut stdout = proc.stdout.take().expect("Failed to take stdout.");
let mut s = [0u8; 5];
loop {
dbg!(stdout.read(&mut s));
let vec: Vec<u8> = Vec::from(&s as &[u8]);
println!("Got: {}", String::from_utf8(vec).unwrap());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment