add pty example that runs whoami
Refs: https://github.com/wez/wezterm/issues/27
This commit is contained in:
1 parent
257c864403
commit
015a97e2be
1 file changed
+26
@@ -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();
|
||||
}
|
||||
Reference in new issue
Block a user