| Crates.io | ptyprocess |
| lib.rs | ptyprocess |
| version | 0.5.0 |
| created_at | 2021-07-05 18:30:13.674549+00 |
| updated_at | 2025-09-12 21:46:04.17051+00 |
| description | A library to work with PTY/TTY on Unix systems |
| homepage | https://github.com/zhiburt/ptyprocess |
| repository | https://github.com/zhiburt/ptyprocess |
| max_upload_size | |
| id | 419112 |
| size | 48,899 |
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.
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(())
}
close-range - optimization for faster PtyProcess::spawn (available on FreeBSD and on Linux since 5.9 and glibc 2.34)