Special characters (^M & ^[[D) when I read pxssh::before and write it to a file

Benjamin Kaplan benjamin.kaplan at case.edu
Wed Mar 17 15:51:50 CET 2010


On Wed, Mar 17, 2010 at 9:54 AM, ashwini yal <ashwiniyal at gmail.com> wrote:

> Hi,
>
> I am writing a python script which logs into the machine using pxssh, sends
> a command, reads the response and writes the response to the file.
>
> But, when I open the file in the editor like vi, its showing special
> characters like ^M and ^[[D instead of spaces or newlines.
>
> This is how my code looks like ...
>
> s = pxssh.pxssh()
> s.login(ip, username, password)
>
> cmd = 'xyz'
> s.sendline (cmd)
> s.prompt()
> output = s.before
> fileWrite = open(filePath , 'wb')
> fileWrite.write(output)
> s.prompt()
>
>
> This is how my filePath looks like when I open it using vi editor.
>
> Starting command execution on host xxx.xxx.xxx.xxx
>
>
> D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^M
>
> Command executed successfully ^M
>
> Executing next command ...^M
>
>
I don't know what's going with the ^[[D, but ^M is a carriage return. Your
connection is returning CRLF ("\r\n") for the line endings (which is what
Windows uses for line endings) instead of the Unix line ending, which is
just a line feed "\n".
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100317/c5c54d88/attachment.html>


More information about the Python-list mailing list