Re: [JSch-users] Shell.java not working
Status: Alpha
Brought to you by:
ymnk
From: campo <rob...@gm...> - 2008-04-17 12:06:46
|
Thank you both for your help. The problem was with 'System.in' I am now able to log in and enter commands. I can use: *channel.setInputStream(System.in);* now as long as I use an input file, i.e.: java Shell < unix.script which is exactly what I need. On Thu, Apr 17, 2008 at 9:47 AM, Atsuhiko Yamanaka <ym...@jc...> wrote: > Hi, > > +-From: campo <rob...@gm...> ------- > |_Date: Wed, 16 Apr 2008 21:50:32 +0100 __ > | > |Question: Does anyone know what might be wrong or is there any way of > |altering Exec.java to execute numerous commands in the same session? > Any > |help appreciated. > > It is a known problem. There is a bug in System.in on Windows. > Try the following code on Windows and Unices, > > class foo{ > public static void main(String[] arg){ > try{ > System.in.read(new byte[32*1024], 0, 32*1024); > } > catch(Exception e){ > System.out.println(e); > } > } > } > > You will get an exception on Windows, but not on Unices. > > Anyway, to work around that bug, try following lines > instead of 'channel.setInputStream(System.in);' in Shell.java > > channel.setInputStream(new FilterInputStream(System.in){ > public int read(byte[] b, int off, int len)throws IOException{ > return in.read(b, off, (len>1024?1024:len)); > } > }); > > Please note that 'Shell.java' is just an example to demonstrate > how to use shell channel instantly. > In the practical programs, nobody will try > 'channel.setInputStream(System.in)'. > > > Sincerely, > -- > Atsuhiko Yamanaka > JCraft,Inc. > 1-14-20 HONCHO AOBA-KU, > SENDAI, MIYAGI 980-0014 Japan. > Tel +81-22-723-2150 > +1-415-578-3454 > Fax +81-22-224-8773 > Skype callto://jcraft/ > |