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