Giter Site home page Giter Site logo

tryweirdier / rust-subprocess-communicate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dropbox/rust-subprocess-communicate

0.0 0.0 0.0 12 KB

This implements the python subprocess.communicate tool for rust

License: BSD 3-Clause "New" or "Revised" License

Rust 100.00%

rust-subprocess-communicate's Introduction

#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;
     }

rust-subprocess-communicate's People

Contributors

danielrh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.