pexpect child.before and child.after is empty

前端 未结 1 1059
臣服心动
臣服心动 2021-01-28 01:16
>>> ssh_stuff
[\'yes/no\', \'Password:\', \'password\', \'Are you sure you want to continue connecting\']
>>> prompt
[\'$\', \'#\']
>>> child          


        
相关标签:
1条回答
  • 2021-01-28 01:48

    The expect method takes a pattern or a list of patterns. These patterns are treated as regular expressions. This is maybe not so clear from the documentation, but if you look into the code of pexpect, then you can see that it is the case.

    The prompt variable is given as

    prompt = ['$', '#']
    

    The $ is a special character in regular expression, which will match according to python regex documentation:

    '$' Matches the end of the string or just before the newline at the end of the string, and in MULTILINE mode also matches before a newline.

    We can see that it is the one being matched in the console output:

    >>> child.expect(prompt)
    0
    

    To interpret the $ sign as a literal it must be preceded by a backslash.

    prompt = ['\$', '#']
    
    0 讨论(0)
提交回复
热议问题