How to use expect with optional prompts?

前端 未结 2 1652
野的像风
野的像风 2021-02-04 09:43

Let\'s say I am trying to write an expect script for a test.sh that has three prompts: prompt1, prompt2, prompt3.

My code is like this:



        
相关标签:
2条回答
  • 2021-02-04 10:04

    As long as you have a case that will be always be expected to hit and don't include an exp_continue in that case, you can can remove duplication and handle optional prompts easily:

    expect "prompt1"
    send "pass1"
    expect { 
        "prompt2" { 
            send "pass2"
            exp_continue
        }
        "prompt3" {
            send "pass3"
        }
    }
    
    0 讨论(0)
  • 2021-02-04 10:10

    You can expect multiple things:

    expect { 
        "prompt2" { 
            send "pass2"
            expect "prompt3"
            send "pass3"
        }
        "prompt3" {
            send "pass3"
        }
    }
    
    0 讨论(0)
提交回复
热议问题