https://github.com/zhiburt/ptyprocess
A process abstraction to work with PTY/TTY on Unix systems
https://github.com/zhiburt/ptyprocess
Last synced: 2 months ago
JSON representation
A process abstraction to work with PTY/TTY on Unix systems
- Host: GitHub
- URL: https://github.com/zhiburt/ptyprocess
- Owner: zhiburt
- License: mit
- Created: 2021-06-29T11:08:34.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2025-09-12T21:44:49.000Z (9 months ago)
- Last Synced: 2026-02-13T15:45:27.814Z (4 months ago)
- Language: Rust
- Homepage:
- Size: 114 KB
- Stars: 15
- Watchers: 1
- Forks: 8
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ptyprocess [](https://github.com/zhiburt/ptyprocess/actions/workflows/ci.yml) [](https://codecov.io/gh/zhiburt/ptyprocess) [](https://crates.io/crates/ptyprocess) [](https://docs.rs/ptyprocess/0.1.0/ptyprocess/) [](./LICENSE.txt)
A library provides an interface for a unix [PTY/TTY](https://en.wikipedia.org/wiki/Pseudoterminal).
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
```rust
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)