Crates.io | pty-exec |
lib.rs | pty-exec |
version | 0.1.0 |
source | src |
created_at | 2023-08-02 23:58:58.97563 |
updated_at | 2023-08-02 23:58:58.97563 |
description | A flexible, cross platform pty package |
homepage | |
repository | |
max_upload_size | |
id | 933248 |
size | 14,872 |
use std::os::fd::{AsRawFd, FromRawFd};
use pty_exec::Pty;
// spawn Pty
let pty = Pty::spawn(move |_fd, res| {
println!("{}", res.unwrap());
}, move |fd| {
println!("{fd} died");
})?;
// (optional) create new pty, this maintains the on_read and on_death callbacks
// this means a RawFd can be passed to client like in a tauri app
let pty = unsafe { Pty::from_raw_fd(pty.as_raw_fd()) };
// write to original pty with new pty from_raw_fd
pty.write("echo 'Hello, World'\r")?;
pty.kill();