Process.exec returning no output - command taking longer than 5 seconds

Discussion in 'Java' started by the_one, Mar 1, 2012.

  1. the_one

    the_one

    Joined:
    Mar 1, 2012
    Messages:
    2
    Hi All,

    I have java program, which executes a external command and captures/prints the output. This is a simple program and used to work earlier, but after we upgraded to new version(which upgraded the command as well), it has stopped producing ouput (i.e. BufferedReader is empty even though the command executes successfully).

    I tried to nail it down and found that the external command now takes longer (<5seconds) than earlier(<1second). I see this similar behavior with "java -version". In other words, if i execute `javac` this snippet works fine, fails only with `java -version`

    Given below is the code snippet:

    Code:
    Process p = Runtime.getRuntime().exec("[COLOR="DarkRed"]java -version[/COLOR]" );
    //p.waitFor();
    InputStream b = p.getInputStream();
    InputStreamReader r = new InputStreamReader(b);
    BufferedReader s = new BufferedReader(r);
    
    String data;
    while ((data = s.readLine()) != null)   {
    	System.out.println (data);
    }
    
    I cannot go with a separate thread (like they use StreamGobbler/StreamEater) because we have this piece of code at about 30 places and creating seperate threads for each would be nightmare.

    Can some one suggest a way to handle this?

    Regards,
    TA
     
    Last edited: Mar 1, 2012
    the_one, Mar 1, 2012
    #1
    1. Advertising

  2. the_one

    the_one

    Joined:
    Mar 1, 2012
    Messages:
    2
    did the trick.
     
    Last edited: Mar 5, 2012
    the_one, Mar 5, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. reachrekhakn@gmail.com

    Socket recv function taking longer time

    reachrekhakn@gmail.com, Dec 26, 2008, in forum: Python
    Replies:
    1
    Views:
    564
    Gabriel Genellina
    Dec 26, 2008
  2. Daniel Pitts
    Replies:
    1
    Views:
    331
    Tom Anderson
    Apr 9, 2010
  3. anshu
    Replies:
    2
    Views:
    163
    anshu
    Sep 21, 2004
  4. Colin Steadman
    Replies:
    2
    Views:
    268
    Colin Steadman
    Oct 14, 2004
  5. Michael Tan
    Replies:
    32
    Views:
    991
    Ara.T.Howard
    Jul 21, 2005
Loading...

Share This Page