Runtime.exec does not work for commands with lengthy outputs

I need to use Runtime.exec to run some custom commands on a Unix box. I have been doing this for quite some time now and had begun to feel comfortable when recently I started facing a problem. The thing is, whenever there is a command which prints a lot of data on to the console, the program is not able to exit from the waitFor method. Is there some thing that can be done about this?
Following is a part of the code I use:
Runtime rt = Runtime.getRuntime();
Process p = rt.exec (command);
System.out.println ("Got the process");
int exitValue = p.waitFor();
System.out.println ("Exit value: " + exitValue);When the output of the "command" is lengthy, it hangs after printing "Got the process".
PS: By lengthy output, I mean that the command results in printing lines to the console which might be more than 100 in number. Say, something like what "ls -R /" would do in Unix / Linux.

From java.lang.Process API doc:
The Runtime.exec methods may not work well for special processes on certain native platforms, such as native windowing processes, daemon processes, Win16/DOS processes on Microsoft Windows, or shell scripts. The created subprocess does not have its own terminal or console. All its standard io (i.e. stdin, stdout, stderr) operations will be redirected to the parent process through three streams (Process.getOutputStream(), Process.getInputStream(), Process.getErrorStream()). The parent process uses these streams to feed input to and get output from the subprocess. Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.
So you need to consume the process' output. Check the StreamGobbler example from this article.
Hope it helps.

Similar Messages

  • Runtime.exec() does not work normally

    I try to wrapper the oracle connect command on unix using this function:
    runtime.exec("sqlplus username/password@dbinstance")
    it is ok on windows, but on unix, after runing the class, I get nothing. what is the problem?
    Please help me. thanks

    There are several traps with runtime.exec(). The most important one is that you should read
    the output stream of the launched program. Otherwise it will stop running when the console buffer overflows. The size of the buffer differs for various OSes.
    Look at this article:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    It it does not answer your problem, try to search the forums:
    http://search.java.sun.com/Search/java?qt=%2B%22exec%22+-%22Replies%3A+0%22&col=javafrm&rf=0&qp=%2Bforum%3A31
    This problem has been asked hundreds of times.
    Hope, this helps.

  • Runtime.exec() does not work?

    I'm trying to invoke a C++ executable from java using the Runtime.exec() method. The C++ application accepts a filename as a command line argument & opens the file. This C++ app is unicode enabled i.e. it can accept UTF-16 (wide char) parameters. Howevere, when i invoke this application using Java's Runtime.exec() and specify a japanese file name as an argument, the japanese characters get converted to '?' characters by the time they are received in the C++ application. I'm running this application on Windows 2K, default i.e. English version.
    Looking at the source code of Runtime class, it seems that the exec()
    function makes use of a native helper function - execInternal(). Does
    this function support the entire unicode range?
    Is there any way we can avoid the conversion of japanese characters to '?' characters? Also, is there any other alternative for invoking an external application with Unicode (Say, japanese) arguments?
    Please reply ASAP.
    Thanks!

    >
    I'm trying to invoke a C++ executable from java using
    the Runtime.exec() method. The C++ application accepts
    a filename as a command line argument & opens the
    file. This C++ app is unicode enabled i.e. it can
    accept UTF-16 (wide char) parameters. Howevere, when i
    invoke this application using Java's Runtime.exec()
    and specify a japanese file name as an argument, the
    japanese characters get converted to '?' characters by
    the time they are received in the C++ application. I'm
    running this application on Windows 2K, default i.e.
    English version.
    Looking at the source code of Runtime class, it seems
    that the exec()
    function makes use of a native helper function -
    execInternal(). Does
    this function support the entire unicode range?I don't know because I've never tested this case specifically.
    You didn't show your code though. How are you reading in the String? You mentioned that you passed a Japanese character String as a filename argument. I also read that you are running on an English Win2K platform. How did you read that argument in? It may just be that you read the argument in your default encoding(English) and you needed to specify an alternate one.

  • Runtime.exec() does not work under Linux

    Hi,
    I have a generic application runner class that runs an external
    program and redirects stdout/stderr to a buffer/file.
    While everythings works just fine under Windows, I get the
    following exception under Linux trying to run the Java interpreter
    'java':
    java.io.IOException: "/usr/lib/SunJava2-1.3.1/jre/bin/java": not found
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:139)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.exec(Runtime.java:546)
    at java.lang.Runtime.exec(Runtime.java:413)
    I have checked that the file /usr/lib/SunJava2-1.3.1/jre/bin/java
    exists.
    Any help appreciated!
    Marc

    can I ask how you solved it? I am having a problem
    with quotes just now to and it might help me!I simply tested what the current platform is and
    only used quotes under Windows.
    Marc

  • Substitute Variables VI does not work for names with underbars. What can I do?

    For example, I want to change "p_0=p_1+p_2;" into "x0=x1+x2;". However the VI does not do it and returns just the same formula. Is this the specification? I enclosed a sample VI to show it.
    Attachments:
    SubTest.vi ‏44 KB

    You problem is in "Find String Identifier" (a subVI of "Substitue Variables") - it searches your variables and tries to split any other characters out of it (it only accepts alphanumeric and spaces as variable names, not special characters - hence your "p_0" becomes "p", and then "p" is not found in your substitution rules, so the original is piped through instead.
    Copyright © 2004-2015 Christopher G. Relf. Some Rights Reserved. This posting is licensed under a Creative Commons Attribution 2.5 License.

  • ODI 11g 11.1.1.7 with Win64 bit OS : Starange problem : Right click does not work for Create new data server in Topology.

    ODI 11g 11.1.1.7 with Win64 bit OS : Strange problem : Right click does not work for Create new data server in Topology.
    On right click nothing happens at all. I have  reinstall the ODI multiple times with right installer. issue persist.
    Please help.

    Hi,
    Did you use the generic installer or the win32 one ? You should use the former with Win64.
    You can also check that your version of Java is supported in the certification matrix.
    Regards,
    JeromeFr

  • Select All in a table does not work for Drag and Drop

    Hi. I am using Jdeveloper 11.1.1.2 but have also reproduced in 11.1.1.3.
    I am trying to implement drag and drop rows from one table to another. Everything works fine except when I do a Select All (ctrl-A) in a table, the table visually looks like all rows are selected, but when I try to click on one of the selected rows to drag to the other table, only the row I click on is dragged.
    I tried setting Range Size -1, fetch mode to FETCH_ALL, content delivery to "immediate" but nothing works.
    I even have reproduced not using a view object but just a List of beans with only 5 or 10 beans showing in the table.
    Does anyone know how to get Select All to work for a Drag Source?
    Thanks.
    -Ed

    Frank-
    OK, thanks for looking into that. I also submitted this service request, which includes a simple sample app to demonstrate the problem:
    SR #3-2387481211: ADF Drag and Drop does not work for rows in table using Select All
    Thanks again for the reply.
    -Ed

  • Auto backlight does not work on 4S with iOS 7! With iOS 6.1.3 I had the same problem.Why?

    Auto backlight does not work on 4S with iOS 7. I had the same problem with iOS 6.1.3! Why ?

    rlwebb71 wrote:
    ... I have the latest generation iPod touch, not the 5, but the latest. So why can't Siri come out and play? 
    Siri is not a feature of that iPod... 4th Gen...
    iOS 6  Which Software for Which iDevices...
    http://support.apple.com/kb/HT5457

  • In Robohelp 9, search does not work for some Vietnamese characters.

    In Robohelp 9, search does not work for some Vietnamese characters.

    I don't think there is anything we can do on a user to user forum. I suggest you report this to Adobe as a bug. Please follow this link.
    http://www.Adobe.com/cfusion/mmform/index.cfm?name=wishform&product=38
    If you need a more immediate response, you would need to take that up with Adobe support.
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

  • CF10 64bit  Apache connector (mod_jk.so) does not work for Apache2.4.3 (windows)

    CF10 64bit  Apache connector (mod_jk.so) does not work for Apache2.4.3 (win64), where can I get a module that works?
    I get this error from Apache :
    C:\www\Apache2.4\bin>httpd -t
    httpd: Syntax error on line 741 of C:/www/Apache2.4/conf/httpd.conf: Syntax error on line 2 of C:/www/Apache2.4/conf/mod_jk.conf: Cannot load C:\\ColdFusion10\\config\\wsconfig\\1\\mod_jk.so into server: The specified procedure could not be found.
    I have already tried manually extracting the pre-built mod_jk22.so from the wsconfig.jar with same results.
    If I switch to Apache 2.2.22 64bit, it does work.  what I need is to be able to run on Apache 2.4.

    Please check out this link.
    http://rob.brooks-bilson.com/index.cfm/2012/2/21/Installing-ColdFusion-10-with-Apache-on-W indows
    In this link, they are configuring with Apache 2.2 only.
    When we were working colfusion 9 with Linux and apache, we had the same problem, it will work when it connect to Apache 2.0 but not with Apache 2.2 version.

  • SM36/37: Specification "After Job" does not work for Daily "periodcity"

    I reviewed http://help.sap.com/saphelp_nw04/helpdata/en/20/2d513897110872e10000009b38f889/content.htm, which states what I am trying to do should work, but it does not.
    Here's the deal:
    1.  I have two jobs: "A" and "B".
    2.  "A" runs Daily.
    3.  I set-up job "B" to run "After job" "A" in my SM36 definition.
    Job "B" will run the next day, but never runs again after that even though job "A" continues to run "Daily" as it should.
    Further info:
    1.  We have "Event-triggered" jobs that run fine, but the "After Job" designation doesn't seem to work ongoingly.
    2.  I can review both jobs "A" and "B" for any "Predecessor" or "Successor" jobs, and, the first jobs to run after the initial set-up DO reference each other (in other words, let's say I schedule job "B" to run "After job" "A" on Tuesday.  After Tuesday's run, Job "A" sees job "B" as it's "Successor" job and job "B" sees job "A" as it's "Predecessor" job), but the definition doesn't last into the next day ONLY FOR JOB "B" (as I mentioned, job "A" always runs fine).
    3.  I can't set the "periodcity" for job "B" because, once I flag it to run "After Job" "A", the "period" options disappear.
    4.  One final tidbit: the variant for job "B" has a "key date" specified so the date is dynamic for each day the job runs.  I can set up job "B" to run "Daily" with this variant and it runs fine, but I wanted it to run AFTER job "A" so it never runs if job "A" doesn't run.  (At this point, it's becoming a matter of principal!)
    Here's my question:
    Why won't job "B" continue to run "Daily" after job "A" (a "Daily" job) runs?
    Thanks in advance,
    Lara

    Please close this thread since you posted the same question here:
    [SM36/37: Specification "After Job" does not work for Daily "periodcity"|SM36/37: Specification "After Job" does not work for Daily "periodcity";

  • TableView : sort = "SERVER" ...does not work for "TIME"

    Hi,
    TableView sort = "Server" works automatically for "Date" Fields and "Text" Fields.
    But it does not work for "Time" field with data element "CDUZEIT". It shows the below error message:
    Note
    The following error text was processed in the system IFD : Invalid sort field type in "SORT ... AS TEXT".
    The error occurred on the application server ifdmain_IFD_01 and in the work process 0 .
    The termination type was: RABAX_STATE
    The ABAP call stack was:
    Form: IF_HTMLB_ELEMENT_DELEGATED~DO_AT_END of program CL_HTMLB_TABLEVIEW============CP
    Form: DELEGATED_END of program CL_HTMLB_ELEMENT==============CP
    Form: IF_BSP_ELEMENT~DO_AT_END of program CL_HTMLB_TABLEVIEW============CP
    Form: ONLAYOUT of program CLO27OLHO7EA9KVWPONPDC2NLTDFHCP
    Form: %_ONLAYOUT of program CL_O27OLHO7EA9KVWPONPDC2NLTDFHCP
    Form: DO_REQUEST of program CL_BSP_PAGE===================CP
    Form: CALL_VIEW of program CL_BSP_PAGE_BASE==============CP
    Form: CALL_VIEW of program CL_BSP_CONTROLLER=============CP
    Form: DO_REQUEST of program ZCL_ZPR_C_ACTION_LOG==========CP
    Form: DO_REQUEST of program CL_BSP_CTRL_ADAPTER===========CP
    Thanks and Regards,
    Bindiya

    Welcome to SDN.
    This problem and solution to it is exaplined in the following oss note number.
    <a href="https://service.sap.com/~form/handler?_APP=01100107900000000342&_EVENT=REDIR&_NNUM=893210&_NLANG=E">893210</a>
    Regards
    Raja

  • "Track Shipment" is iOS4 does not work for Canada Post tracking numbers

    Not 100% sure this is the best forum to post this but couldn't find an iOS specific forum.
    When an email arrives with a shipment tracking number embedded in it, iOS4 is smart enough to recognize it and turn it into a link. You click the link, select "Track Shipment" and in theory you get sent off to the appropriate shipment tracking website.
    Problem is that this does not work for Canada Post tracking numbers, I get sent to the USPS tracking site instead of the Canada Post one. I assume that the number format is similar but there must be a way to distinguish between CPC tracking numbers and USPS tracking numbers (by range ?).

    This has since become working in 4.0 and higher.
    I noticed I now get a notes folder for each of my email accounts (ie. in my case; MobileMe gets one, Gmail gets another, and Virgin Media a yet another). And all three since accordingly correctly between Notes mailbox on iPhone 4 and it's counterpart Notes mailbox in the mac mail app under Reminders section.
    Additionally, just like other main mailboxes (inbox, drafts, sent, trash, junk), they also have a "unified" box at the top in both mac and iphone, in order to view notes in all email accounts at the same time.
    Hooray Apple, shame it took so long, but at least it's here now

  • 7.1.2 update failed. Now my iPhone 5 is in recovery mode and hard resetting does not work for me. iTunes also will not detect my phone now

    I did my 7.1.2 update via iTunes. Half way through it stopped working saying it does not detect my phone. Now my iPhone 5 is in recovery mode and hard resetting does not work for me. iTunes also will not detect my phone now

    Thank you SO very much for posting this. I had the exact issue with my iPad Mini after the same upgrade. Hard reset failed, computer would not recognize iPad. I had read all the other instructions and nothing worked.... YOUR SOLUTION WORKED FOR ME - with a slight variation.
    I followed your lead and connected my iPad Mini to another computer, fired up iTunes, it saw the iPad Mini in Restore Mode and allowed me to go into Restore (yes, it wiped all of the data but I have a back up on the other computer that would not see it after the failed update). It installed the latest iOS 7.1.2 as well. I then disconnected it from that computer, reconnected it to the computer that would not see it prior and it then saw it as a new iPad and allowed me to Restore my backup and now it's all good!
    I detailed my steps only because you downloaded the previous version - 7.1.1 whereas I downloaded the latest version (7.1.2) and then restored my back up.

  • Notification center does not work at all with mail

    notification center does not work at all with mail there is no sonud no banner . i try to chek and unchek thas box may it is something may effect but still not working where is the notifiication center they said to us about it but i want be fair it's working for imessege and it's not working also for app store update like they said there is abig kiind of joke. i use macbook air mid 2011.

    Have you changed the system voice to an English one in system preferences?

Maybe you are looking for

  • Safari doesn't open up...

    even with another user account won't open, I also tried trash the prefs, the cache and i did repair disk permissions can anyone help me? thank you this is the report: Process: Safari [23720] Path: /Applications/Safari.app/Contents/MacOS/Safari Identi

  • Disfunctional Keyboard Number Pad

    I've been having weird problems with my keyboard's number pad.  Initially, it starts off fine when I boot up the computer.  However, it eventually starts acting funny.  The number keys on it act like num lock is turned off, regardless of it's state. 

  • How to set a window title...

    Let me start with the basics: If you create an extension, the Stage Manager will create the container for you and load the swf into the container. This container can be one of three types: Panel, Model Dialog, or Modeless Dialog. Any one of these con

  • RME Archive Sync fails

    I have two  7206 routers that I can't get the configs from. I have double checked credentials. The failures show as: CM0151 PRIMARY RUNNING Config fetch failed for ber10 Cause: TELNET: Failed to establish TELNET connection to xxx.xxx.xxx.xxx - Cause:

  • Wanting to know more about using my iphone to skype

    Hi, everyone.. i did a quick serach about skype on the forum but there is not much information about it. So i'm going to ask you guys a bit more using the iphone to skype. Me and my husband both of us got iphone4 and many of our friends as well. So c