4

If I run a normal interactive python session, input/output looks like this:

>>> 1 + 1;
2

Now I'm trying to run it through socat, so I start a "server"

socat UNIX-LISTEN:$HOME/socket,fork EXEC:python,pty,stderr

And connect to it from another terminal:

socat - UNIX-CONNECT:$HOME/socket

Which works almost fine except the input is echoed again too:

>>> 1 + 1;
1 + 1;
2

How can I turn this off? echo=0 does not do what I want: this hides the input while I'm typing as well which is not very helpful. I want it to work just like a normal interactive session.

(using python and a local domain socket is just an example; the same occurs with other programs (e.g. cat, lua etc.) and other socket types, e.g. a TCP socket.

  • READLINE and "noecho" on the man page, which appears to be different from "echo=0"? – user2267 Oct 31 '14 at 19:06
  • Nope. That too does not echo anything while I'm typing, until I press ENTER. I want to see and be able to edit while I type, just not have the line echoed back again after I press ENTER. – user21105 Nov 1 '14 at 20:28
6

write either this on client side . notice the "raw" .

socat unix-connect:socket -,raw,echo=0

or this on server side . notice the "echo=0"

socat unix-listen:socket exec:"python",pty,echo=0

but not both . alternatively raw on client stdio with echo=0 on the server pty is fine , but echo=0 must not be applied twice .


lets look at the two 1+1's . they are echos but with different meanings . the first echo is from line buffering of the client terminal , and the second is from the terminal on the server side created by socat .

>>> 1 + 1;
1 + 1;
2

use of echo=0 alone on client stdio , socat informs its controlling terminal ( i.e. xterm or anything like ) to disable the echoing ( on-screen-display ) of stdio buffer , thus the first 1+1 disappears , and the second will show in the very place once return key is pressed . echo=0 on server pty prevents socat from echoing ( ping-pong ) the input it receives back to the client , thus the second 1+1 disappears . with raw on the client , buffering of stdio is disabled so every key don't wait till a return to be sent to the server , and server echos the key back immediatly . use raw on client stdio along with echo=0 on client stdio when a key is pressed it is first sent to the server then the server sends it back and is displayed on the client . use raw on client stdio along with echo=0 on server pty when a key is pressed it is displayed simultanously as it is sent to the server , but is never sent back .


for commandline editing , sometimes it is sufficient to buffer a line on the client side and not send a whole line until we finish editing this line . however if powerful smart completion is desired , server side involvement is necessary .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy