-->

sending SIGINT CTRL-C using ganymed SSH2?

2019-06-04 22:36发布

问题:

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();