1
1
mirror of https://github.com/wez/wezterm.git synced 2024-09-21 11:50:42 +03:00
wezterm/pty/examples/whoami.rs

27 lines
642 B
Rust
Raw Normal View History

use portable_pty::{CommandBuilder, PtySize, PtySystemSelection};
fn main() {
let pty_system = PtySystemSelection::default().get().unwrap();
let (master, slave) = pty_system
.openpty(PtySize {
rows: 24,
cols: 80,
pixel_width: 0,
pixel_height: 0,
})
.unwrap();
let cmd = CommandBuilder::new("whoami");
let mut child = slave.spawn_command(cmd).unwrap();
let mut s = String::new();
master
.try_clone_reader()
.unwrap()
.read_to_string(&mut s)
.unwrap();
println!("output: {}", s);
child.wait().unwrap();
}