我使用JSch来拖尾远程计算机中的文件.但我发现程序退出后,
“tail -f”进程仍然存在于远程计算机中.
如果我删除“-f”参数,一切都OK.
我试过使用“sendSignal()”,但它不起作用.似乎OpenSSH没有实现该功能.
这是测试代码.
public static void main(String[] args) throws Exception {
String usr = args[0];
String host = args[1];
String password = args[2];
JSch jsch = new JSch();
Session session = jsch.getSession(usr,host);
String pwd = password;
session.setPassword(pwd);
Hashtable
最佳答案
execCommand没有为通道分配控制tty,因此tail实际上正在写入管道.它将一直持续到向它发送更多数据(它将获得一个SIGPIPE).
最简单的解决方案是分配tty – 使用:
m_channelExec.setPty(true);
在m_channelExec.connect()之前的行;
哪个应该给你想要的行为.