Created
August 10, 2017 15:39
-
-
Save levicole/9ae7870f75afefb62eb402cf3ae42948 to your computer and use it in GitHub Desktop.
Watch output of tail in rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::process::{Command, Stdio, ChildStdout}; | |
use std::io::{Read}; | |
use std::thread; | |
use std::str; | |
fn main() { | |
let mut command = Command::new("/usr/bin/tail"); | |
command | |
.arg("-f") | |
.arg("/var/log/system.log") | |
.stdout(Stdio::piped()); | |
if let Ok(child) = command.spawn() { | |
if let Some(mut out) = child.stdout { | |
loop { | |
let mut chars: [u8; 10] = [0; 10]; | |
out.read(&mut chars).expect("didn't work"); | |
print!("{}", str::from_utf8(&chars).unwrap()); | |
} | |
} | |
} else { | |
println!("Process failed to start"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment