expect_line/
expect_line.rs1use expectrl::{self, Any, Eof};
2
3#[cfg(not(feature = "async"))]
4fn main() {
5 let mut session = expectrl::spawn("ls -al").expect("Can't spawn a session");
6
7 loop {
8 let m = session
9 .expect(Any::boxed(vec![
10 Box::new("\r"),
11 Box::new("\n"),
12 Box::new(Eof),
13 ]))
14 .expect("Expect failed");
15
16 println!("{:?}", String::from_utf8_lossy(m.as_bytes()));
17
18 let is_eof = m[0].is_empty();
19 if is_eof {
20 break;
21 }
22
23 if m[0] == [b'\n'] {
24 continue;
25 }
26
27 println!("{:?}", String::from_utf8_lossy(&m[0]));
28 }
29}
30
31#[cfg(feature = "async")]
32fn main() {
33 futures_lite::future::block_on(async {
34 let mut session = expectrl::spawn("ls -al").expect("Can't spawn a session");
35
36 loop {
37 let m = session
38 .expect(Any::boxed(vec![
39 Box::new("\r"),
40 Box::new("\n"),
41 Box::new(Eof),
42 ]))
43 .await
44 .expect("Expect failed");
45
46 let is_eof = m.get(0).unwrap().is_empty();
47 if is_eof {
48 break;
49 }
50
51 if m.get(0).unwrap() == [b'\n'] {
52 continue;
53 }
54
55 println!("{:?}", String::from_utf8_lossy(m.get(0).unwrap()));
56 }
57 })
58}