diff --git a/pty/examples/whoami.rs b/pty/examples/whoami.rs new file mode 100644 index 000000000..8171163ff --- /dev/null +++ b/pty/examples/whoami.rs @@ -0,0 +1,26 @@ +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(); +}