can we exit without error from telnet with MozRepl?

天涯浪子 提交于 2020-01-06 15:51:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!