sending control charactors to external process in Java

只愿长相守 提交于 2019-12-01 13:17:06

Control-] in ASCII is equivalent to 035 octal. In Java you can represent this as "\035".

Writer writer = new OutputStreamWriter(process.getOutputStream());
writer.write("\035");
writer.flush();

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.

OutputStream os = process.getOutputStream();
os.write(29);
os.flush();

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.

Writer writer = new OutputStreamWriter(process.getOutputStream());
writer.write("exit\n");
writer.flush();

You can also, obviously, close the OutputStream which closes the STDIN of the remote process.

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