pub fn spawn_bash(timeout: Option<u64>) -> Result<PtyReplSession, Error>
Expand description

Spawn bash in a pty session, run programs and expect output

The difference to spawn and spawn_command is:

  • spawn_bash starts bash with a custom rcfile which guarantees a certain prompt
  • the PtyBashSession also provides wait_for_prompt and execute

timeout: the duration until which exp_* returns a timeout error, or None additionally, when dropping the bash prompt while bash is still blocked by a program (e.g. sleep 9999) then the timeout is used as a timeout before a kill -9 is issued at the bash command. Use a timeout whenever possible because it makes debugging a lot easier (otherwise the program just hangs and you don’t know where)

bash is started with echo off. That means you don’t need to “read back” what you wrote to bash. But what you need to do is a wait_for_prompt after a process finished.

Also: if you start a program you should use execute and not send_line.

For an example see the README