Skip to content

Commit

Permalink
add pty example that runs whoami
Browse files Browse the repository at this point in the history
Refs: #27
  • Loading branch information
wez committed May 20, 2019
1 parent 257c864 commit 015a97e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions pty/examples/whoami.rs
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit 015a97e

Please sign in to comment.