Crates.io | pty-process |
lib.rs | pty-process |
version | 0.4.0 |
source | src |
created_at | 2021-03-06 08:20:53.438358 |
updated_at | 2023-08-07 00:51:24.992448 |
description | spawn commands attached to a pty |
homepage | |
repository | https://git.tozt.net/pty-process |
max_upload_size | |
id | 364698 |
size | 56,390 |
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 = pty_process::Pty::new().unwrap();
pty.resize(pty_process::Size::new(24, 80)).unwrap();
let mut cmd = pty_process::Command::new("nethack");
let child = cmd.spawn(&pty.pts().unwrap()).unwrap();
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.
By default, only the blocking
APIs are available. To
include the asynchronous APIs, you must enable the async
feature.