expect module does not work with multiple prompts

Hi

I have this task:

`
tasks:

  • expect:
    command: /path/to/bash/script.sh
    responses:
    '#? ': ‘5’
    “[y/N]”: ‘y’
    `

expect module correctly responds to first prompt, but not to second. It responds to second prompt with ‘5’ when it should respond with ‘y’.

When I enable echo=yes, I see:

`

“#? 5”

“[y/N]5”


`

You can easily reproduce it with bash script and two echo/read

Edgars

I believe the problem is that pexpect treats all matches as regex. You have specified ‘#?’ which means the # is optional, effectively making the regex an empty string.

An empty string matches anything, so pexpect will send the response for ‘#?’ for everything.

You probably want:

responses:
'#? ': ‘5’
“[y/N]”: ‘y’

I think that should like help out.

Thanks a lot Matt, it worked.

I was confused a bit because I saw that p/expect actually found the match (both of them), so I did not think that it could be regex issue

Thanks again

Edgars

piektdiena, 2015. gada 4. septembris 14:01:06 UTC+2, Matt Martz rakstīja:

Hi,

I ran across a problem with expect response the same value to all prompt.

I have a task that execute a command and expecting four prompt the expect module response to the first prompt correctly but response to the 2nd & 3rd prompt with the same value from the 1st prompt.

  • expect:
    command: /path/to/the/script.sh
    responses:
    ‘.?:$': ‘12345’
    '.
    ?:$’: ‘12345’
    ‘.?:$': ‘xena-warrior’
    '.
    ?:$’: ‘12345’

echo: yes

All prompts have end of line ‘:’

From the output I can see the reponse ‘12345’ in the third prompt and not ‘xena-warrior’.

Any help would greatly appreciated,

David.

All of your “questions” are the same. Because you are defining a hash/dict for responses, by providing the same key you are over writing the values.

If you need to respond multiple times to a question with different answers, this is not currently possible with the released version of the expect module but will be included in the next release.