blindsnowmobile blindsnowmobile - 9 days ago 7
Bash Question

Expect script not sending new line correctly

I'm using expect to respond to a network service. However, I've noticed in Wireshark, when I do the following:

send "mystring\r\n"


it gets translated on the wire to:


"mystring\n"


I've tried setting
stty raw
, and various combinations of
\r
,
\n
, as well as sending ASCII codes from within expect. Expect seems to be translating any of these combinations to
\n
. The problem is the server seems to require a
\r\n
in order to accept the input. I've been able to determine this, because when I use "interact" from within expect, and then type a
^M
(control-v enter) from the shell, Wireshark sees a string of:


"mystring \r\n"


sent out over the wire, and the server processes the input correctly. Is there a way to properly send this combination through expect without the translation?

Answer

Are you doing the stty directly or by using set stty_init raw in the expect script? (expect's stty command operates on your terminal, not the pty.) You may also want to look at the -nottyinit option to spawn.