based on this answer, I am trying to figure out a way to exit from telnet and it return 0
these wont work:
(echo -e "repl.quit()";sleep 1) |telnet localhost 4242;echo $?
(echo -e "\029";sleep 1;echo "q";sleep 1) |telnet localhost 4242;echo $?
(echo -e "\c]";sleep 1;echo "q";sleep 1) |telnet localhost 4242;echo $?
(echo -e "\e]";sleep 1;echo "q";sleep 1) |telnet localhost 4242;echo $?
(echo -e "\E]";sleep 1;echo "q";sleep 1) |telnet localhost 4242;echo $?
The problem is: I am UNABLE to differentiate from a successful exit and a failed one...
I think this question can be linked.
You need to send
^]
character, that is an unprintable group separator character before your telnet client terminates your connection after executing all commands you gave it via pipe. Most versions ofecho
program can produce unprintable characters using-e
option. Group separator is 035 in octal (you can see the entire ASCII table withman 7 ascii
on *nix systems.). So, the entire command should look like this: