1#[cfg(unix)]
2use expectrl::{repl::spawn_bash, ControlCode, Error, Expect};
3
4#[cfg(feature = "async")]
5use expectrl::AsyncExpect;
6
7#[cfg(unix)]
8#[cfg(not(feature = "async"))]
9fn main() -> Result<(), Error> {
10 let mut p = spawn_bash()?;
11 p.send_line("ping 8.8.8.8")?;
12 p.expect("bytes of data")?;
13 p.send(ControlCode::try_from("^Z").unwrap())?;
14 p.expect_prompt()?;
15 p.send_line("bg")?;
17 p.expect("ping 8.8.8.8")?;
18 p.expect_prompt()?;
19 p.send_line("sleep 0.5")?;
20 p.expect_prompt()?;
21 p.send_line("fg")?;
23 p.expect("ping 8.8.8.8")?;
24 p.send(ControlCode::try_from("^D").unwrap())?;
25 p.expect("packet loss")?;
26
27 Ok(())
28}
29
30#[cfg(unix)]
31#[cfg(feature = "async")]
32fn main() -> Result<(), Error> {
33 futures_lite::future::block_on(async {
34 let mut p = spawn_bash().await?;
35 p.send_line("ping 8.8.8.8").await?;
36 p.expect("bytes of data").await?;
37 p.send(ControlCode::Substitute).await?; p.expect_prompt().await?;
39 p.send_line("bg").await?;
41 p.expect("ping 8.8.8.8").await?;
42 p.expect_prompt().await?;
43 p.send_line("sleep 0.5").await?;
44 p.expect_prompt().await?;
45 p.send_line("fg").await?;
47 p.expect("ping 8.8.8.8").await?;
48 p.send(ControlCode::EndOfText).await?;
49 p.expect("packet loss").await?;
50 Ok(())
51 })
52}
53
54#[cfg(windows)]
55fn main() {
56 panic!("An example doesn't supported on windows")
57}