14 releases

0.5.0 Sep 12, 2025
0.4.1 Mar 6, 2023
0.3.0 Dec 11, 2021
0.2.0 Oct 7, 2021
0.1.9 Jul 28, 2021

#335 in Command-line interface

Download history 5543/week @ 2025-11-01 4280/week @ 2025-11-08 4121/week @ 2025-11-15 4712/week @ 2025-11-22 3974/week @ 2025-11-29 3584/week @ 2025-12-06 3449/week @ 2025-12-13 2806/week @ 2025-12-20 2902/week @ 2025-12-27 3926/week @ 2026-01-03 4564/week @ 2026-01-10 5411/week @ 2026-01-17 5608/week @ 2026-01-24 8562/week @ 2026-01-31 7367/week @ 2026-02-07 8857/week @ 2026-02-14

31,371 downloads per month
Used in 36 crates (4 directly)

MIT license

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

use ptyprocess::PtyProcess;

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 World!")?;

    // 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(())
}

Features

  • close-range - optimization for faster PtyProcess::spawn (available on FreeBSD and on Linux since 5.9 and glibc 2.34)

Dependencies

~2MB
~39K SLoC