1

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.

  • 2
    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. – Usman Saleem Dec 17 '12 at 04:59
  • thanks,like i said in my question i try direct ssh but i dont say that i use ssh from ubuntu, that works, the same code that i try to use in windows i used it in my ubuntu and also works, but with windows dont, so only can be FreeSSHd, but i read that is the best free ssh for windows and the most easy to install, any ssh server suggestion? thanks. – Diego Fernando Murillo Valenci Dec 17 '12 at 14:48
  • @Usman Saleem your suggestion was right, i install openssh in my windows and all works fine, thanks :D – Diego Fernando Murillo Valenci Dec 17 '12 at 16:20
  • No issues Diego :), I will add my comment as an answer so that you can accept it. – Usman Saleem Dec 17 '12 at 22:47
  • http://stackoverflow.com/questions/17221127/funny-shell-output-0132mtestfile-txt00m-instead-of-testfile-txt i found it! –  Jul 31 '13 at 08:30

2 Answers2

1

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.

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
  • 1
    U+FFFD indicates that there was a conversion from Unicode to a legacy character set which lost information in the process *OR* there was an invalid code unit sequence (applicable to UTF-8 and UTF-16). It has nothing to do with fonts. – Joey Dec 17 '12 at 06:41
  • thanks, the windows is in spanish language so the diamond/question is really ó (versión), how i can set a font in this case for that?, and how i can use the correct terminal emulation? Jsch has a method like channel.setPty maybe is what i need? – Diego Fernando Murillo Valenci Dec 17 '12 at 14:53
1

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.

Usman Saleem
  • 1,665
  • 9
  • 18