Question

I am trying to execute a command in windows XP with Jsch Shell channel, but for some reason i get weird symbols in my System.out stream and the commands cannot be executed, the code that i use for connect is this:

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

Then i get The following message:

[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

And when i try to call a cd C:\MyFolder\ then another command (all tested from a ssh client and works) i gen more weird symbols and dont get the results of my commands, What can be the problem? Following is the commands that i send and the result:

exec.print.println("cd C:\\MyFolder\\");
exec.print.println("some other command");

result:

[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

I am using a FreeSShd in windows xp and the program runs on Ubuntu, i use ssh in my console and works with the windows XP, i am trying to implement it in my java program, thanks for any help.

Was it helpful?

Solution

Have you tried direct ssh? If direct ssh works, then its jsch. Try jsch with a linux based ssh server. If jsch works then it is FreeSshd issue.

OTHER TIPS

This is an encoding problem plus a lack of terminal emulation.

The SSH daemon expects to talk to a device that understands terminal control sequences (the [1;1H string, which is actually preceded by an ESC character). Your program does not provide terminal emulation, so you see the raw escape sequences.

The diamond/question-mark character indicates that the font you are using doesn't contain the character sent by the server. In this case it may be an accented character.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top