Crate pty_process

Source
Expand description

This crate is a wrapper around tokio::process::Command or std::process::Command which provides the ability to allocate a pty and spawn new processes attached to that pty, with the pty as their controlling terminal. This allows for manipulation of interactive programs.

The basic functionality looks like this:

let (mut pty, pts) = pty_process::open()?;
pty.resize(pty_process::Size::new(24, 80))?;
let mut cmd = pty_process::Command::new("nethack");
let child = cmd.spawn(pts)?;
let (mut pty, pts) = pty_process::blocking::open()?;
pty.resize(pty_process::Size::new(24, 80))?;
let mut cmd = pty_process::blocking::Command::new("nethack");
let child = cmd.spawn(pts)?;

The returned child is a normal instance of tokio::process::Child (or std::process::Child for the blocking variant), with its stdin/stdout/stderr file descriptors pointing at the given pty. The pty instance implements tokio::io::AsyncRead and tokio::io::AsyncWrite (or std::io::Read and std::io::Write for the blocking variant), and can be used to communicate with the child process. The child process will also be made a session leader of a new session, and the controlling terminal of that session will be set to the given pty.

§Features

By default, only the blocking APIs are available. To include the asynchronous APIs, you must enable the async feature.

Modules§

blocking
Blocking equivalents for pty_process::Command and pty_process::Pty

Structs§

Commandasync
Wrapper around tokio::process::Command
OwnedReadPtyasync
Owned read half of a Pty
OwnedWritePtyasync
Owned write half of a Pty
Ptsasync
The child end of the pty
Ptyasync
An allocated pty
ReadPtyasync
Borrowed read half of a Pty
Size
Represents the size of the pty.
WritePtyasync
Borrowed write half of a Pty

Enums§

Error
Error type for errors from this crate

Functions§

openasync
Allocate and return a new pty and pts.

Type Aliases§

Result
Convenience wrapper for Results using Error