aboutsummaryrefslogtreecommitdiffstats
path: root/examples/basic.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-12-28 03:33:52 -0500
committerJesse Luehrs <doy@tozt.net>2021-12-28 05:28:28 -0500
commitf8780ca1e76286688b74d8a6c64d5fadf3cfd2a1 (patch)
treeb1e0fe6a378f3a8810e0332ca572a86185fd556c /examples/basic.rs
parentb181b63a69d5db78769c1c3723a9940f66491466 (diff)
downloadpty-process-f8780ca1e76286688b74d8a6c64d5fadf3cfd2a1.tar.gz
pty-process-f8780ca1e76286688b74d8a6c64d5fadf3cfd2a1.zip
wip
Diffstat (limited to 'examples/basic.rs')
-rw-r--r--examples/basic.rs28
1 files changed, 16 insertions, 12 deletions
diff --git a/examples/basic.rs b/examples/basic.rs
index bee6758..1e5913b 100644
--- a/examples/basic.rs
+++ b/examples/basic.rs
@@ -5,7 +5,7 @@ mod main {
use std::io::{Read as _, Write as _};
use std::os::unix::io::AsRawFd as _;
- pub fn run(child: &pty_process::std::Child) {
+ pub fn run(child: &mut pty_process::std::Child) {
let _raw = super::raw_guard::RawGuard::new();
let mut buf = [0_u8; 4096];
let pty = child.pty().as_raw_fd();
@@ -34,11 +34,7 @@ mod main {
stdout.flush().unwrap();
}
Err(e) => {
- // EIO means that the process closed the other
- // end of the pty
- if e.raw_os_error() != Some(libc::EIO) {
- eprintln!("pty read failed: {:?}", e);
- }
+ eprintln!("pty read failed: {:?}", e);
break;
}
};
@@ -62,21 +58,29 @@ mod main {
break;
}
}
+ match child.try_wait() {
+ Ok(Some(_)) => break,
+ Ok(None) => {}
+ Err(e) => {
+ println!("wait failed: {:?}", e);
+ break;
+ }
+ }
}
}
}
#[cfg(feature = "backend-std")]
fn main() {
- use pty_process::Command as _;
use std::os::unix::process::ExitStatusExt as _;
- let mut child = std::process::Command::new("sleep")
- .args(&["500"])
- .spawn_pty(Some(&pty_process::Size::new(24, 80)))
- .unwrap();
+ let pty = pty_process::std::Pty::new().unwrap();
+ pty.resize(pty_process::Size::new(24, 80)).unwrap();
+ let mut cmd = pty_process::std::Command::new("tac");
+ // cmd.args(&["500"]);
+ let mut child = cmd.spawn(pty).unwrap();
- main::run(&child);
+ main::run(&mut child);
let status = child.wait().unwrap();
std::process::exit(