I am connecting to “/bin/bash” in ubuntu using:
process = Runtime.getRuntime().exec(cmd);
Here cmd is a String with different commands that i read and write from process.
Now i have come across a situation, where i login to remote machiens using ssh and while reading writing information to ext process, for loggin out from remote machine, i have to send control character like:
CTRL + ] in order to logout the session gracefully and come back to my local machine. Assuming the cmd is a String type, how can i write this CTRL chracter to the process?
Control-] in ASCII is equivalent to 035 octal. In Java you can represent this as “\035”.
It is also equivalent to decimal value of 29 so if you can write a byte with a value of 29 then that will work as well.
I assume
Control-]has to do with the remote program. You are talking about telnet? However writing “exit\n” will also close the remote bash.You can also, obviously, close the
OutputStreamwhich closes the STDIN of the remote process.