On Dec 31 2007, 6:46 pm, crybaby <[EMAIL PROTECTED]> wrote:
> 1) what are these characters:
> \x1b]0;
> ~\x07\x1b[?1034h
>
> in line '\x1b]0;[EMAIL PROTECTED]:[EMAIL PROTECTED] ~]'?
These are probably escape sequences in your shell prompt string.
Typically they are interpreted by the terminal, like xterm, to update
title bar.
>
> 2) Also, how come I don't get 0 or 2(excuting ls command exit code)
> from result.split('\r\n')[0] or result.split('\r\n')[1] ?
I don't think your expect worked fine to capture the desired output.
>
> This is what I get:>>> import pexpect
> >>> child=pexpect.spawn('ssh [EMAIL PROTECTED]')
> >>> child.sendline("ls mytest.log > /dev/null 2>&1; echo $?")
> 41
> >>> child.before
> >>> print child.before
> None
> >>> print child.after
> None
before/after makes sense only after an expect. At this point there is
only a sendline; not expect. So the above None output is expected.
> >>> child.expect([pexpect.TIMEOUT, '\$ '])
> 1
1 implies it matched the second pattern. You want to use raw strings.
r'\$' or else the re sent down is a plain $ which re interprets as end
of buffer.
Most important here is your prompt doesn't end with a $ (it's
something like [EMAIL PROTECTED] ~]). Thus make it,
child.expect(r'.*]')
Try the ls command and rest of the statements.
Karthik
> >>> result=child.before
> >>> print result.split('\r\n')[1]
> [EMAIL PROTECTED] ~]
> >>> print result.split('\r\n')[0]
>
> Last login: Mon Dec 31 20:52:09 2007 from com1>>> print result.split('\r\n')
>
> ['Last login: Mon Dec 31 20:52:09 2007 from com1\r',
> '\x1b]0;[EMAIL PROTECTED]:[EMAIL PROTECTED] ~]']
--
http://mail.python.org/mailman/listinfo/python-list