Having the ; exit at the end so you terminate the shell process is brilliant!!!!!

I wish I would've thought of that! :)

Just for the record, it works great!

Thank's a lot!

-Mihai




> Date: Wed, 17 Sep 2008 10:59:06 +0900
> To: baietas@hotmail.com
> CC: jsch-users@lists.sourceforge.net
> Subject: Re: [JSch-users] How do you capture output of a command executed on Shell?
> From: ymnk@jcraft.com
>
> Hi,
>
> +-From: Mike V <baietas@hotmail.com> -----
> |_Date: Mon, 15 Sep 2008 21:06:30 +0000 __
> |
> |How do you capture output of a command executed on Shell and how do you
> |know if it is done executing?
> |I need this because some programs look for variables set by the .profile
> |(ksh).
> ...
>
> I have not tried it by myself yet, but ....
>
> /*
> | commandToRun=commandToRun + " > "+tempFile+"\n"
> */
> commandToRun=commandToRun + " > "+tempFile+"; exit\n"
>
> | byte[] bytes = commandToRun.getBytes();
> | ByteArrayInputStream bais=new ByteArrayInputStream(bytes);
> |try { ..... //session connection stuff
> | .....
> | Channel channel=session.openChannel("shell");
> | ((ChannelShell)channel).setInputStream(bais);
>
> InputStream in=channel.getInputStream();
>
> | channel.connect();
>
> byte[] tmp=new byte[1024];
> while(true){
> while(in.available()>0){
> int i=in.read(tmp, 0, 1024);
> if(i<0)break;
> }
> if(channel.isClosed()){
> break;
> }
> try{Thread.sleep(1000);}catch(Exception ee){}
> }
>
>
> 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/


Upgrade to Hotmail Plus and share more photos with bigger attachments. Click here to find out how Click here to find out how