bash/bash.rs
1//! This example shows an example of interacting with a
2//! `bash` shell session. It opens a `bash` session,
3//! sends some command (`echo` and `ls`), and waits for `bash`
4//! to respond. Then it closes the stdin stream by
5//! calling `close()`, and waits for `bash` to exit.
6
7use interactive_process::InteractiveProcess;
8use std::{process::Command, thread::sleep, time::Duration};
9
10fn main() {
11 let mut cmd = Command::new("/usr/bin/bash");
12 let mut proc = InteractiveProcess::new(&mut cmd, |line| {
13 println!("Got: {}", line.unwrap());
14 })
15 .unwrap();
16
17 sleep(Duration::from_millis(10));
18
19 proc.send("echo 'Hi from bash. Running ls:'").unwrap();
20 proc.send("ls").unwrap();
21
22 sleep(Duration::from_millis(10));
23
24 proc.close();
25}