I am unable to get Telnet to send only CR (\r) at the end of a command, despite setting the crlf toggle to <CR><NUL> (see example below). Instead, Telnet always sends CR-LF (\r\n).
My goal: retrieve data from a remote device connected to a cell-modem through an RS-232 port. Currently, I’m using Telnet to send my requests for the data. I have good reasons to believe this is possible, and I need to be able to scale up and automate.
Requirements: the remote device requires that commands end only in CR.
My understanding of the problem: I assume the extra LF is causing the device to fail to properly read my commands. More specifically, I think the LF is left over from each command, and added to the beginning of the next command. I infer this because the very first time I issue a command to the remote device after resetting the device, I actually get the correct response. All subsequent responses, however, indicate the device did not understand the command.
Details: if I launch Telnet, and set it to return hex values (set netdata, plus set prettydump to make it easier to read), I can see that the lines end in CR (hex=0d) and LF (hex=0a) even though asked Telnet to end the lines in only CR plus NULL. I.e., I expected the last character to be 00, not 0a. See snippet below (host and port replaced with "x"). FYI: "QD" is my command, which asks the device to report the current date, and "BADD" is the device's response when it doesn't understand a command.
$ telnet
telnet> toggle crlf
Will send carriage returns as telnet <CR><LF>.
telnet> toggle crlf
Will send carriage returns as telnet <CR><NUL>.
telnet> set netdata
Will print hexadecimal representation of network traffic.
telnet> set prettydump
Will print user readable output for "netdata".
telnet> open x.x.x.x xxxx
Trying x.x.x.x xxxx...
Connected to x.x.x.x.
Escape character is '^]'.
QD
> 0x0 51 44 0d 0a
< 0x0 42 41 44 44 0d 0a
BADD
Platforms I have tested: Ubuntu 18.04.1 using Telnet, inetutils-telnet, and PuTTY; Windows 7 using Cygwin, PuTTY, and TeraTerm; Windows 10 using PuTTY.
Similar post: Any way to send just "\n" in Telnet? – the question in this other post, however, was the reverse: the line endings needed to be LF only.
Summary of question: how do I get Telnet to send only CR at the ends of lines?
QD?$ nc x.x.x.x xxxx, Enter, thenQD. Does the device need to be set to listening mode using netcat first? If so, that's not going to be possible. When I put Telnet into binary mode, the ending is LF only, regardless of whether I type Enter or Ctrl-M, which seems really weird, and I get no response from the device. The Ctrl-M idea was clever, so I tested that on my original example, but that made no difference: it ended the line with CRLF as before. @Scott: In my original example I was typing Enter afterQD.$ printf 'QD\r' | nc -w 5 x.x.x.x xxxx.netcatrather thantelnet. I bet most of this weirdness is coming from theicrnlterminal mode setting. Usestty -ato confirm that it's set.icrnlconverts CRs into LFs, so yourtelnetandnetcatare never actually seeing CR from the keyboard. You canstty -icrnlto let CR pass untranslated (andstty icrnlto revert) but then you'll need to use ctrl-J to indicate end-of-line.