[Python telnetlib read_until recv problem]
"read_until" function returns cut off string with long commands.
The commands ran perfectly, but it does not show full texts.
How can I fix this? Please help.
# my code
tn = telnetlib.Telnet(ip, 23, 5)
prompt = ']# '
tn.write('echo "this is a long command for the test purpose... > test.txt"\n')
print tn.read_until(prompt, 1)
# debug output
Telnet(192.168.220.4,23): send 'echo "this is a long command for the test purpose... > test.txt"\n'
Telnet(192.168.220.4,23): recv 'echo "this is a l'
Telnet(192.168.220.4,23): recv 'ong command for the test purpose... > te\r\x00<his is '
Telnet(192.168.220.4,23): recv 'a long command for the test purpose... > tes '
Telnet(192.168.220.4,23): recv ' \x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x0
8t.txt"'
Telnet(192.168.220.4,23): recv '\r\nthis is a long command for the test purpose... >'
Telnet(192.168.220.4,23): recv ' test.txt\r\n[root@RHEL6-5 tmp]# '
# real output
<his is a long command for the test purpose... > test.txt"
this is a long command for the test purpose... > test.txt
[root@RHEL6-5 tmp]#
Working for me.
The issue appears to be occurring due to line-wrapping. I found a solution where setting the window size width to near the max value allows long lines to be received without line-wrapping applied by the telnet server.
(See the Window Size Option RFC for details on setting the option https://www.ietf.org/rfc/rfc1073.txt )