Skip to content

Commit 25453f2

Browse files
Merge pull request #26 from TyPR124/use_ptyproc
Windows Support
2 parents f07478a + b670237 commit 25453f2

File tree

6 files changed

+134
-344
lines changed

6 files changed

+134
-344
lines changed

Cargo.lock

Lines changed: 44 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ readme = "README.md"
1414

1515

1616
[dependencies]
17-
nix = "0.14"
1817
regex = "1"
1918
error-chain = "0.12"
2019
tempfile = "3"
20+
ptyproc = { version = "0.1", git = "https://github.com/TyPR124/ptyproc" }
21+
2122

2223
[badges]
2324
travis-ci = { repository = "philippkeller/rexpect" }

examples/exit_code.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,40 @@ extern crate rexpect;
22

33
use rexpect::spawn;
44
use rexpect::errors::*;
5-
use rexpect::process::wait;
6-
75

86
/// The following code emits:
97
/// cat exited with code 0, all good!
108
/// cat exited with code 1
119
/// Output (stdout and stderr): cat: /this/does/not/exist: No such file or directory
1210
fn exit_code_fun() -> Result<()> {
13-
14-
let p = spawn("cat /etc/passwd", Some(2000))?;
11+
let mut p = spawn("cat /etc/passwd", Some(2000))?;
1512
match p.process.wait() {
16-
Ok(wait::WaitStatus::Exited(_, 0)) => println!("cat exited with code 0, all good!"),
17-
_ => println!("cat exited with code >0, or it was killed"),
13+
Ok(status) if status.success() => println!("cat exited with code 0, all good!"),
14+
Ok(status) => {
15+
if let Some(code) = status.code() {
16+
println!("Cat failed with exit code {}", code);
17+
println!("Output (stdout and stderr): {}", p.exp_eof()?);
18+
} else {
19+
println!("cat was probably killed")
20+
}
21+
},
22+
Err(err) => println!("failed to wait on process {:?}", err),
1823
}
19-
24+
2025
let mut p = spawn("cat /this/does/not/exist", Some(2000))?;
2126
match p.process.wait() {
22-
Ok(wait::WaitStatus::Exited(_, 0)) => println!("cat succeeded"),
23-
Ok(wait::WaitStatus::Exited(_, c)) => {
24-
println!("Cat failed with exit code {}", c);
25-
println!("Output (stdout and stderr): {}", p.exp_eof()?);
27+
Ok(status) if status.success() => println!("cat exited with code 0, all good!"),
28+
Ok(status) => {
29+
if let Some(code) = status.code() {
30+
println!("Cat failed with exit code {}", code);
31+
println!("Output (stdout and stderr): {}", p.exp_eof()?);
32+
} else {
33+
println!("cat was probably killed")
34+
}
2635
},
27-
// for other possible return types of wait()
28-
// see here: https://tailhook.github.io/rotor/nix/sys/wait/enum.WaitStatus.html
29-
_ => println!("cat was probably killed"),
36+
Err(err) => println!("failed to wait on process {:?}", err),
3037
}
31-
38+
3239
Ok(())
3340
}
3441

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,14 @@
7878
//!
7979
//! ```
8080
81-
pub mod process;
8281
pub mod session;
8382
pub mod reader;
8483

8584
pub use session::{spawn, spawn_bash, spawn_python, spawn_stream};
8685
pub use reader::{Until};
8786

87+
pub use ptyproc::{Command, PtyProcess, PtyReader, PtyWriter};
88+
8889
pub mod errors {
8990
use std::time;
9091
// Create the Error, ErrorKind, ResultExt, and Result types

0 commit comments

Comments
 (0)