Created
September 5, 2019 14:57
-
-
Save itsfarseen/b8db22122ae4f48af7ed6fff6f2c4b54 to your computer and use it in GitHub Desktop.
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 nix::fcntl; | |
use nix::sys::select; | |
use std::io::Read; | |
use std::os::unix::io::AsRawFd; | |
use std::process; | |
fn main() { | |
let mut path = std::env::current_exe().unwrap(); | |
path.set_file_name("teller"); | |
let mut proc = process::Command::new(&path) | |
.stdout(process::Stdio::piped()) | |
.spawn() | |
.unwrap(); | |
let mut stdout = proc.stdout.take().expect("Failed to take stdout."); | |
let fd = stdout.as_raw_fd(); | |
let mut flags = | |
fcntl::OFlag::from_bits(fcntl::fcntl(fd, fcntl::F_GETFL).expect("Failed reading flags")) | |
.expect("Failed parsing flags"); | |
flags.insert(fcntl::OFlag::O_NONBLOCK); | |
fcntl::fcntl(fd, fcntl::F_SETFL(flags)).expect("Failed to set flags."); | |
let mut s = String::new(); | |
loop { | |
let mut fds = select::FdSet::new(); | |
fds.insert(fd); | |
dbg!(select::select(None, &mut fds, None, None, None)); | |
dbg!(stdout.read_to_string(&mut s)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment