1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
//! Execution and interaction with external processes. //! //! The module has two entry points. One is the [`Popen`] struct, //! inspired by Python's `subprocess.Popen`. This is useful when a //! greater amount of control is needed, or when porting Python code //! written for Python's `subprocess`. The other entry point is the //! [`Exec`] struct written in the builder style more native to Rust, //! similar to `std::process::Command`. //! //! # Examples //! //! Create [`Popen`] directly in order to communicate with a process and //! optionally terminate it: //! //! ```ignore //! let mut p = Popen::create(&["ps", "x"], PopenConfig { //! stdout: Redirection::Pipe, ..Default::default() //! })?; //! //! // Since we requested stdout to be redirected to a pipe, the parent's //! // end of the pipe is available as p.stdout. It can either be read //! // directly, or processed using the communicate() method: //! let (out, err) = p.communicate(None)?; //! //! // check if the process is still alive //! if let Some(exit_status) = p.poll() { //! // the process has finished //! } else { //! // it is still running, terminate it //! p.terminate()?; //! } //! ``` //! //! Use the [`Exec`] builder to execute a command and capture its //! output: //! //! ```ignore //! let output = Exec::cmd("command").arg("arg1").arg("arg2") //! .stdout(Redirection::Pipe) //! .capture()? //! .stdout_str(); //! ``` //! //! [`Popen`]: struct.Popen.html //! [`Exec`]: struct.Exec.html #![warn(missing_docs)] extern crate libc; #[cfg(windows)] extern crate kernel32; #[cfg(windows)] extern crate winapi; mod popen; mod builder; #[cfg(unix)] mod posix; #[cfg(windows)] mod win32; mod os_common; pub use self::os_common::ExitStatus; pub use self::popen::{Popen, PopenConfig, Redirection, PopenError, Result}; pub use self::builder::{Exec, NullFile, Pipeline}; #[cfg(test)] mod tests { mod common; #[cfg(unix)] mod posix; #[cfg(windows)] mod win32; mod builder; }