ptyprocess

Crates.ioptyprocess
lib.rsptyprocess
version0.4.1
sourcesrc
created_at2021-07-05 18:30:13.674549
updated_at2023-03-06 08:07:41.386918
descriptionA library to work with PTY/TTY on Unix systems
homepagehttps://github.com/zhiburt/ptyprocess
repositoryhttps://github.com/zhiburt/ptyprocess
max_upload_size
id419112
size45,156
Maxim Zhiburt (zhiburt)

documentation

https://docs.rs/ptyprocess

README

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(())
}
Commit count: 161

cargo fmt