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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
//! # PTY //! //! [![Crate][crate-badge]][crate] [![docs-badge][]][docs] [![license-badge][]][license] [![travis-badge][]][travis] //! //! [crate-badge]: https://img.shields.io/badge/crates.io-v0.2.0-orange.svg?style=flat-square //! [crate]: https://crates.io/crates/pty //! //! [docs-badge]: https://img.shields.io/badge/API-docs-blue.svg?style=flat-square //! [docs]: http://note.hibariya.org/pty-rs/pty/index.html //! //! [license-badge]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square //! [license]: https://github.com/hibariya/pty-rs/blob/master/LICENSE.txt //! //! [travis-badge]: https://travis-ci.org/hibariya/pty-rs.svg?branch=master&style=flat-square //! [travis]: https://travis-ci.org/hibariya/pty-rs //! //! The `pty` crate provides `pty::fork()`. That makes a parent process fork with new pseudo-terminal (PTY). //! //! This crate depends on followings: //! //! * `libc` library //! * POSIX environment //! //! ## Usage //! //! Add this to your `Cargo.toml`: //! //! ```toml //! [dependencies] //! pty = "0.2" //! ``` //! //! and this to your crate root: //! //! ```rust //! extern crate pty; //! ``` //! //! ### pty::fork() //! //! This function returns `pty::Child`. It represents the child process and its PTY. //! //! For example, the following code spawns `tty(1)` command by `pty::fork()` and outputs the result of the command. //! //! ```rust //! extern crate pty; //! extern crate libc; //! //! use std::ffi::CString; //! use std::io::Read; //! use std::ptr; //! //! use pty::fork::*; //! //! fn main() { //! let fork = Fork::from_ptmx().unwrap(); //! //! if let Some(mut master) = fork.is_parent().ok() { //! // Read output via PTY master //! let mut output = String::new(); //! //! match master.read_to_string(&mut output) { //! Ok(_nread) => println!("child tty is: {}", output.trim()), //! Err(e) => panic!("read error: {}", e), //! } //! } //! else { //! // Child process just exec `tty` //! let cmd = CString::new("tty").unwrap().as_ptr(); //! let args = [cmd, ptr::null()].as_mut_ptr(); //! //! unsafe { libc::execvp(cmd, args) }; //! } //! } //! ``` #![crate_type = "lib"] #![cfg_attr(feature = "nightly", feature(plugin))] #![cfg_attr(feature = "lints", plugin(clippy))] #![cfg_attr(feature = "lints", deny(warnings))] #![deny( missing_debug_implementations, missing_copy_implementations, trivial_casts, trivial_numeric_casts, unstable_features, unused_import_braces, unused_features, unused_qualifications, )] extern crate libc; extern crate errno; mod ffi; mod descriptor; pub mod fork; pub mod prelude; const DEFAULT_PTMX: &'static str = "/dev/ptmx";