#pty #tty #terminal

ptyprocess

A library to work with PTY/TTY on Unix systems

11 releases

0.3.0 Dec 11, 2021
0.2.0 Oct 7, 2021
0.1.9 Jul 28, 2021

#291 in Command-line interface

Download history 81/week @ 2022-03-11 52/week @ 2022-03-18 83/week @ 2022-03-25 67/week @ 2022-04-01 10/week @ 2022-04-08 4/week @ 2022-04-15 35/week @ 2022-04-22 113/week @ 2022-04-29 242/week @ 2022-05-06 217/week @ 2022-05-13 80/week @ 2022-05-20 105/week @ 2022-05-27 444/week @ 2022-06-03 136/week @ 2022-06-10 158/week @ 2022-06-17 243/week @ 2022-06-24

1,016 downloads per month
Used in 2 crates (via expectrl)

MIT license

29KB
523 lines

ptyprocess Build codecov Crate docs.rs license

A library provides an interface for a unix PTY/TTY.

It aims to work on all major Unix variants.

The library was developed as a backend for a https://github.com/zhiburt/expectrl. If you're interested in a high level operations may you'd better take a look at zhiburt/expectrl.

Usage

use ptyprocess::PtyProcess;
use std::process::Command;
use std::io::{BufRead, Write, BufReader};

fn main() {
    // spawn a cat process
    let mut process = PtyProcess::spawn(Command::new("cat")).expect("failed to spawn a process");

    // create a communication stream
    let mut stream = process.get_raw_handle().expect("failed to create a stream");

    // send a message to process
    writeln!(stream, "Hello cat").expect("failed to write to a stream");

    // read a line from the stream
    let mut reader = BufReader::new(stream);
    let mut buf = String::new();
    reader.read_line(&mut buf).expect("failed to read a process output");

    println!("line={}", buf);

    // stop the process
    assert!(process.exit(true).expect("failed to stop the process"))
}

Dependencies

~1.5MB
~28K SLoC