proc-reader

Crates.ioproc-reader
lib.rsproc-reader
version0.5.1
sourcesrc
created_at2018-04-09 11:06:26.07866
updated_at2023-05-16 01:17:52.972337
descriptionA std::io::Read implementation for stdout/stderr of other proccess
homepage
repositoryhttps://github.com/dalance/proc-reader
max_upload_size
id59702
size32,922
Naoya Hatta (dalance)

documentation

README

proc-reader

Build Status Crates.io Docs.rs codecov

A std::io::Read implementation for stdout/stderr of other process

Documentation

Usage

[dependencies]
proc-reader = "0.5.1"

Supported Platform

  • x86_64-unknown-linux-gnu
  • x86_64-unknown-linux-musl
  • i686-unknown-linux-gnu
  • i686-unknown-linux-musl

Example

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);
}
Commit count: 76

cargo fmt