#pty #tty #terminal

ptyprocess

A library to work with PTY/TTY on Unix systems

13 releases

0.4.1 Mar 6, 2023
0.4.0 Mar 5, 2023
0.3.0 Dec 11, 2021
0.2.0 Oct 7, 2021
0.1.9 Jul 28, 2021

#417 in Command-line interface

Download history 1948/week @ 2024-07-20 2231/week @ 2024-07-27 2372/week @ 2024-08-03 2965/week @ 2024-08-10 1848/week @ 2024-08-17 2715/week @ 2024-08-24 2076/week @ 2024-08-31 2588/week @ 2024-09-07 4909/week @ 2024-09-14 5230/week @ 2024-09-21 2174/week @ 2024-09-28 1913/week @ 2024-10-05 2298/week @ 2024-10-12 3287/week @ 2024-10-19 2567/week @ 2024-10-26 2573/week @ 2024-11-02

10,975 downloads per month
Used in 22 crates (4 directly)

MIT license

29KB
519 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::io::{BufRead, BufReader, Result, Write};
use std::process::Command;

fn main() -> Result<()> {
    // spawn a cat process
    let mut process = PtyProcess::spawn(Command::new("cat"))?;

    // create a communication stream
    let mut stream = process.get_raw_handle()?;

    // send a message to process
    writeln!(stream, "Hello cat")?;

    // read a line from the stream
    let mut reader = BufReader::new(stream);
    let mut buf = String::new();
    reader.read_line(&mut buf)?;

    println!("line was entered {buf:?}");

    // stop the process
    assert!(process.exit(true)?);

    Ok(())
}

Dependencies

~1.5MB
~35K SLoC