通过java(Jsch)上的SSH连接到Windows时的奇怪符号



我正在尝试使用 Jsch Shell 通道在 Windows XP 中执行命令,但由于某种原因,我的 System.out 流中出现了奇怪的符号并且命令无法执行,我用于连接的代码是这样的:

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 SettingsdiegoEscritorio>[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 SettingsdiegoEscritorio>[4;44H[4;1HC:Documents and SettingsdiegoEscritorio>c[4;58H[4;1HC:Documents and SettingsdiegoEscritorio>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 问题。

这是一个编码问题,加上缺乏终端仿真。

SSH 守护程序希望与理解终端控制序列([1;1H字符串,实际上前面有一个ESC字符)的设备通信。 您的程序不提供终端仿真,因此您会看到原始转义序列。

菱形/问号字符表示您使用的字体不包含服务器发送的字符。 在这种情况下,它可能是重音字符。

最新更新