3

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?

1 Answer 1

5

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.

4
  • Ah... within my script, I do: stty raw I missed stty_init on the man page. I'll give it a try tomorrow and see how it goes. Thanks! Apr 11, 2012 at 6:15
  • 3
    So, I was able to resolve the issue. I had to use set stty_init raw prior to spawning my command. In addition, I also had to send the \r\n in hex: send "mystring\x0d\x0a". That did the trick. Apr 12, 2012 at 3:24
  • How on earth did you figure out to send hex chars? Working for me as well, but surely there's a better solution than this?
    – jonathan
    Jan 31, 2019 at 16:51
  • That worked but now newlines don't get rendered correclty :( Mar 2, 2020 at 21:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.