Hi, Thanks you very much. This solved my problem. I have written separate methods for error and input streams and calling one after another. As you suggested when I modified my code and joined them the control is coming back to jsch after the command execution. Just one more doubt. I have to also use other oracle commands such as imp. Do all the oracle commands write to err stream?
Regards, P.V.R.Kartik -----Original Message----- From: Keith Alan Richardson [mailto:[email protected]] Sent: Wednesday, November 17, 2010 4:13 PM To: Kartik Pullabhotla v r (WT01 - GMT-Telecom Equipment) Cc: [email protected] Subject: Re: FW: [JSch-users] Oracle exp command with jsch Your code is reading only one input stream (in variable) . Based on later emails you sent, I believe that is standard out. Oracle's exp command writes exclusively to stderr. You must read both streams or your application will block. Below is some sample code. (please note: we suspect a deadlock in our application when reading large output of 17MB. The code below may contain that bug so use as-is at your own risk) InputStream in = channel.getInputStream(); channel.connect(); InputStream err_in = channel.getExtInputStream(); byte[] tmp = new byte[1024]; while (true) { while (in.available() > 0) { int i = in.read(tmp, 0, 1024); if (i < 0) break; stdOut += new String(tmp, 0, i); } while (err_in.available() > 0) { int i = err_in.read(tmp, 0, 1024); if (i < 0) break; stdErr += new String(tmp, 0, i); } if (channel.isClosed()) { break; } Thread.sleep(500); } Thanks, Keith On Tue, Nov 16, 2010 at 11:10 AM, <[email protected]> wrote: > > (Resending for the group).. > > Hi Alan, > > Thanks for the reply. > > Yes, I am reading both output and error channel. I have run the > following commands in the server and both print fine, i.e., all the > characters are printed. Moreover i could observe in the code that the > input buffer has no content in it AND the channel is never closed. > Please note my source code below which is just exactly as suggested in the > example files. > > StringBuilder tmpBuf = new StringBuilder(); > byte[] tmp = new byte[1024]; > while (true) { > while (in.available() > 0) { > int i = in.read(tmp, 0, 1024); > if (i < 0) > break; > String resp = new String(tmp, 0, i); > tmpBuf.append(resp); > } > if (channel.isClosed()) { > in.close(); > break; > } > //for debug, if miss isClosed() > if( !channel.isClosed() && channel.getExitStatus() == 0 ){ > System.out.println("before close exit-status changed!" ); > } > } > > Here, the inputstream 'in', after few cycles, is returning no > character (in.available < 0) and channel.isClosed() is never true. > > Please advise. > > Regards, > P.V.R.Kartik > ________________________________ > From: Keith Alan Richardson [mailto:[email protected]] > Sent: Tuesday, November 16, 2010 1:14 PM > To: Kartik Pullabhotla v r (WT01 - GMT-Telecom Equipment) > Cc: [email protected] > Subject: Re: [JSch-users] Oracle exp command with jsch > > Are you reading the channel stdout and stderr? One or both buffers > may fill up causing deadlock > > SQL*Plus may not produce enough output to fill the buffers but exp might. > > You can test if this is your problem by running the following commands : > > # print 1MB to stdout > > perl -e 'print "x"x(1*1024*1024)' > > # print 1MB to sterr > > perl -e 'print STDERR "x"x(1*1024*1024)' > > On 16 Nov 2010 09:00, <[email protected]> wrote: > > > (Resending this since i haven't received any acknowlegement or the > copy) > > > Hi Team, > > We have a project here whose primary purpose is to call a script on a > unix server from... > > ---------------------------------------------------------------------- > -------- Beautiful is writing same markup. Internet Explorer 9 > supports standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 > & L3. > Spend less time writing and rewriting code and more time creating > great experiences on the web. Be a part of the beta today > http://p.sf.net/sfu/msIE9-sfdev2dev > _______________________________________________ > JSch-users mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/jsch-users > > Please do not print this email unless it is absolutely necessary. > > The information contained in this electronic message and any > attachments to this message are intended for the exclusive use of the > addressee(s) and may contain proprietary, confidential or privileged > information. If you are not the intended recipient, you should not > disseminate, distribute or copy this e-mail. Please notify the sender > immediately and destroy all copies of this message and any attachments. > > WARNING: Computer viruses can be transmitted via email. The recipient > should check this email and any attachments for the presence of > viruses. The company accepts no liability for any damage caused by any > virus transmitted by this email. > > www.wipro.com ------------------------------------------------------------------------------ Beautiful is writing same markup. Internet Explorer 9 supports standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3. Spend less time writing and rewriting code and more time creating great experiences on the web. Be a part of the beta today http://p.sf.net/sfu/msIE9-sfdev2dev _______________________________________________ JSch-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jsch-users
