Pexpect Child.before And Child.after Is Empty
>>> ssh_stuff ['yes/no', 'Password:', 'password', 'Are you sure you want to continue connecting'] >>> prompt ['$', '#'] >>> child = pexpect.spawn('ssh ku
Solution 1:
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 = ['\$', '#']
Post a Comment for "Pexpect Child.before And Child.after Is Empty"