From 015a97e2bebf4ef9d9044f98df3f4efb1f9fc312 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 20 May 2019 07:20:47 -0700 Subject: [PATCH] add pty example that runs whoami Refs: https://github.com/wez/wezterm/issues/27 --- pty/examples/whoami.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 pty/examples/whoami.rs 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(); +}