subprocess-communicate

Crates.iosubprocess-communicate
lib.rssubprocess-communicate
version0.2.2
sourcesrc
created_at2016-05-31 07:19:50.441421
updated_at2016-11-14 22:52:03.675865
descriptionProvides a communicate primitive similar to python's subprocess.Popen.communicate that allows input to be presented to the process and results to be captured from both stdout and stderr up to an optional bound.
homepagehttps://github.com/dropbox/rust-subprocess-communicate
repositoryhttps://github.com/dropbox/rust-subprocess-communicate
max_upload_size
id5248
size21,544
Daniel (danielrh)

documentation

https://github.com/dropbox/rust-subprocess-communicate/tree/master/README.md

README

#subprocess-communicate crates.io Build Status

Project Requirements

This crate should give an interface to communicating with child processes similar to python's subprocess.communicate interface from the Popen class.

Pass an input u8 slice and the result should be two Vec one for stdout and for stderr Also an error may be returned in case the subprocess pipes were unable to be changed into nonblock mode or the event loop was unable to be activated.

Unlike the python interface, this also supports two optional arguments to bound the maximum output size of stdout and stderr respectively. This is to prevent a process like /usr/bin/yes from actively consuming all system memory and it helps reason about maximum resource consumption

Usage

    let process =
           Command::new("/bin/cat")
           .stdin(Stdio::piped())
           .stdout(Stdio::piped())
           .stderr(Stdio::piped())
           .spawn().unwrap();
     let (ret_stdout, ret_stderr, err) = subprocess_communicate::subprocess_communicate(process, // child subprocess
                                                                                        &TEST_DATA[..], // stdin input
                                                                                        Some(TEST_DATA.len()), // stdout bound
                                                                                        None); // stderr bound (if any)
     err.unwrap();
     assert_eq!(TEST_DATA.len() - 1, ret_stdout.len());
     assert_eq!(0usize, ret_stderr.len());
     let mut i : usize = 0;
     for item in TEST_DATA[0..TEST_DATA.len()].iter() {
         assert_eq!(*item, ret_stdout[i]);
         i += 1;
     }
Commit count: 11

cargo fmt