1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use expectrl::{check, spawn, Error};
#[cfg(not(feature = "async"))]
fn main() {
let mut session = spawn("python ./tests/source/ansi.py").expect("Can't spawn a session");
loop {
match check!(
&mut session,
_ = "Password: " => {
println!("Set password to SECURE_PASSWORD");
session.send_line("SECURE_PASSWORD").unwrap();
},
_ = "Continue [y/n]:" => {
println!("Stop processing");
session.send_line("n").unwrap();
},
) {
Err(Error::Eof) => break,
result => result.unwrap(),
};
}
}
#[cfg(feature = "async")]
fn main() {
futures_lite::future::block_on(async {
let mut session = spawn("python ./tests/source/ansi.py").expect("Can't spawn a session");
loop {
match check!(
&mut session,
_ = "Password: " => {
println!("Set password to SECURE_PASSWORD");
session.send_line("SECURE_PASSWORD").await.unwrap();
},
_ = "Continue [y/n]:" => {
println!("Stop processing");
session.send_line("n").await.unwrap();
},
)
.await
{
Err(Error::Eof) => break,
result => result.unwrap(),
};
}
})
}