问题
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.
回答1:
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 of echo
program can produce unprintable characters using -e
option. Group separator is 035 in octal (you can see the entire ASCII table with man 7 ascii
on *nix systems.). So, the entire command should look like this:
$ (echo "content.location.href = 'http://v4.ident.me/'"; sleep 2; echo -e '\035'; sleep 2) | telnet localhost 4242 > /dev/null
$ echo $?
$ 0
来源:https://stackoverflow.com/questions/24337292/can-we-exit-without-error-from-telnet-with-mozrepl