简体   繁体   English

如何使用JSCH发送CTRL + C?

[英]How to send CTRL+C WITH JSCH?

I'm using jsch ChannelShell to send commands to a remote system, but I can't send special commands like ctrl+c . 我正在使用jsch ChannelShell将命令发送到远程系统,但是无法发送ctrl+c类的特殊命令。 I tried many things, but have no success. 我尝试了很多事情,但没有成功。

Any help would be appreciated. 任何帮助,将不胜感激。

You can simply send a signal. 您可以简单地发送信号。 In your case it will be 2 which corresponds to CTRL+C : 在您的情况下,它将是2,对应于CTRL + C:

channel.sendSignal("2"); // sends (CTRL+C) signal

You can find list of Unix signals here . 您可以在此处找到Unix信号列表。

I think, i figured out my fault. 我想,我发现了我的错。 Cat and grep(and those type of commands) commands are one shot commands. Cat和grep(以及那些类型的命令)命令是一键式命令。 They are not continuous. 它们不是连续的。 So I can't interrupt those commands. 所以我不能打扰那些命令。 I have to stop listening stream to stop printing outputs. 我必须停止监听流以停止打印输出。

if you want to terminate an operation like tail 如果您想终止像tail这样的操作

Example -    BufferedReader reader = new BufferedReader(new InputStreamReader(ce.getInputStream()));
         OutputStream out=ce.getOutputStream();
out.write(3); //terminate the tail command

 out.flush();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM