Crates.io | subprocess-communicate |
lib.rs | subprocess-communicate |
version | 0.2.2 |
source | src |
created_at | 2016-05-31 07:19:50.441421 |
updated_at | 2016-11-14 22:52:03.675865 |
description | Provides 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. |
homepage | https://github.com/dropbox/rust-subprocess-communicate |
repository | https://github.com/dropbox/rust-subprocess-communicate |
max_upload_size | |
id | 5248 |
size | 21,544 |
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
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
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;
}