sending SIGINT CTRL-C using ganymed SSH2?

≯℡__Kan透↙ 提交于 2019-12-08 07:37:43

问题


I need to kill a process that I have started using ganymed SSH2. Specifically I would like to gracefully kill it using Ctrl+C. I have seen ideas of trying to send ASCII \x03 but when using the execCommand() it wont take escaped chars. How can I send Ctrl+C SIGINT through ganymed?

If there is another Java SSH app I should be using let me know, I have looked into Jsch, sshj but just found ganymed ssh2 to the be easiest.

The program i am trying to kill is tethereal (wireshark)


回答1:


I've used this with JSch to successfully send Ctrl+C:

JSch jsch = new JSch();
Session session = jsch.getSession(user, host);
session.setPassword(password);
session.connect(timeout);
Channel channel = session.openChannel("shell");
channel.connect();
OutputStream out = channel.getOutputStream();
...
out.write(3); // send CTRL-C
out.flush();


来源:https://stackoverflow.com/questions/5366923/sending-sigint-ctrl-c-using-ganymed-ssh2

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