Linux Telnet vt100 Return key sends ^M

2019-04-13 18:06发布

问题:

I'm writing Telnet automation scripts with TCL and Expect in Linux Debian. Pressing Return in a Telnet session or within a *.tcl script (send "command\r") and even send "command\n" causes the line being send with ^M (Ctrl+M) at the end. Off course, the remote host treats those commands as illegal. Tried to telnet set crlf prior to the opening of the connection and mode line while connected, but this has no effect. Using Puttys GUI, I've enabled this option to send a new line by pressing Return instead of ^M. Works fine. How do I configure this option for telnet ?

Help would be much appreciated!

Edit:

stty -a

speed 38400 baud; rows 24; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z;      rprnt = ^R;
werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon     -ixoff
-iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke

stty (with stty icrnl enabled)

speed 38400 baud; line = 0;
-brkint -imaxbel

回答1:

The command "stty" might be able to change your end-of-line settings.

First, see what you have currently set:

stty -a

Then try one of the options available.

stty ocrnl

This should translate a carriage return to a new-line.

You can undo this setting with a minus sign:

stty -ocrnl

If that doesn't work take a look at onlret or maybe onlcr.

It's difficult to test this without having your exact environment.