#pty #terminal #tty

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

#358 in Command-line interface

Download history 2026/week @ 2024-06-17 2163/week @ 2024-06-24 1751/week @ 2024-07-01 2255/week @ 2024-07-08 1624/week @ 2024-07-15 1973/week @ 2024-07-22 2263/week @ 2024-07-29 2585/week @ 2024-08-05 2687/week @ 2024-08-12 2346/week @ 2024-08-19 2428/week @ 2024-08-26 1959/week @ 2024-09-02 3105/week @ 2024-09-09 5220/week @ 2024-09-16 4500/week @ 2024-09-23 2005/week @ 2024-09-30

14,955 downloads per month
Used in 21 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