我试图在Windows XP中使用Jsch Shell通道执行命令,但是由于某些原因,我在System.out流中得到了奇怪的符号,并且命令无法执行,我用于connect的代码是这样的:
this.session = jsch.getSession(this.login, this.host);
Properties properties = new Properties();
properties.put("StrictHostKeyChecking", "no");
session.setPassword(this.password);
session.setConfig(properties);
session.connect(30000);
channel =(ChannelShell) session.openChannel("shell");
PipedInputStream pip = new PipedInputStream(40);
channel.setInputStream(pip);
channel.setOutputStream(System.out);
PipedOutputStream pop = new PipedOutputStream(pip);
print = new PrintStream(pop);
channel.connect();
然后我得到以下消息:
[1;1HMicrosoft Windows XP [Versi�n 5.1.2600][2;1H(C) Copyright 1985-2001 Microsoft Corp.[4;1HC:\Documents and Settings\diego\Escritorio>[4;44H
当我尝试调用cd C:\ MyFolder \时,另一个命令(都通过ssh客户端进行了测试并且可以正常工作)我生成了更多奇怪的符号,而没有得到命令的结果,这可能是什么问题?以下是我发送的命令和结果:
exec.print.println("cd C:\\MyFolder\\");
exec.print.println("some other command");
结果:
[1;1HMicrosoft Windows XP [Versi�n 5.1.2600][2;1H(C) Copyright 1985-2001 Microsoft Corp.[4;1HC:\Documents and Settings\diego\Escritorio>[4;44H[4;1HC:\Documents and Settings\diego\Escritorio>c[4;58H[4;1HC:\Documents and Settings\diego\Escritorio>cd C:\MyFolder\[4;58H[4;46H[4;58H[4;47H[4;58H[4;48H[4;58H[4;49H[4;58H[4;50H[4;58H[4;51H[4;58H[4;52H[4;58H[4;53H[4;58H[4;54H[4;58H[4;55H[4;58H[4;56H[4;58H[4;57H[4;58H
我在Windows XP中使用FreeSShd,该程序在Ubuntu上运行,我在控制台中使用ssh并与Windows XP一起使用,我正在尝试在Java程序中实现它,感谢您的帮助。
最佳答案
您是否尝试过直接ssh?如果直接的ssh有效,则它的jsch。在基于Linux的ssh服务器上尝试使用jsch。如果jsch有效,则为FreeSshd问题。