| Crates.io | proc-reader |
| lib.rs | proc-reader |
| version | 0.5.1 |
| created_at | 2018-04-09 11:06:26.07866+00 |
| updated_at | 2023-05-16 01:17:52.972337+00 |
| description | A std::io::Read implementation for stdout/stderr of other proccess |
| homepage | |
| repository | https://github.com/dalance/proc-reader |
| max_upload_size | |
| id | 59702 |
| size | 32,922 |
A std::io::Read implementation for stdout/stderr of other process
[dependencies]
proc-reader = "0.5.1"
extern crate proc_reader;
use proc_reader::ProcReader;
use std::process::Command;
use std::io::Read;
use std::time::Duration;
use std::thread;
fn main() {
// Create a process for reading stdout
let child = Command::new("sh").arg("-c").arg("sleep 1; echo aaa").spawn().unwrap();
// Create ProcReader from pid
let mut reader = ProcReader::from_stdout(child.id());
// Wait the end of process
thread::sleep(Duration::from_secs(2));
// Read from ProcReader
let mut line = String::new();
let _ = reader.read_to_string(&mut line);
assert_eq!( "aaa\n", line);
}