How to catch output from external exe file

Discussion in 'Java' started by Ivan S, Jan 10, 2008.

  1. Ivan S

    Ivan S Guest

    I tried something like this:

    try {
    Process p = Runtime.getRuntime().exec("somepathto\
    \some.exe");

    String line = null;

    BufferedReader read = new BufferedReader(new
    InputStreamReader(p.getInputStream()));

    while((line = read.readLine()) != null) {
    System.out.println(line);
    }
    int exitVal = p.waitFor();
    System.out.println("Exit value = " + exitVal);
    }
    catch (Throwable e) {
    e.printStackTrace();
    }

    ....but it doesn't work.
    When I try to read one by one character (using read() method) it
    produces some output, but not all.

    Can anyone help me? Thanks in advance. :)
     
    Ivan S, Jan 10, 2008
    #1
    1. Advertising

  2. Ivan S

    Roedy Green Guest

    On Thu, 10 Jan 2008 05:42:52 -0800 (PST), Ivan S
    <> wrote, quoted or indirectly quoted someone who
    said :

    > while((line = read.readLine()) != null) {
    > System.out.println(line);


    see http://mindprod.com/jgloss/exec.html for how to do it.
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Jan 10, 2008
    #2
    1. Advertising

  3. Jacek Wojciechowski, Jan 10, 2008
    #3
    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. John Black
    Replies:
    8
    Views:
    4,163
    Xenos
    Aug 20, 2004
  2. Adam
    Replies:
    9
    Views:
    577
    red floyd
    Feb 2, 2006
  3. Marteno Rodia

    catch doesn't catch a thrown exception

    Marteno Rodia, Aug 3, 2009, in forum: Java
    Replies:
    5
    Views:
    572
    Daniel Pitts
    Aug 5, 2009
  4. Thijs Janzen
    Replies:
    2
    Views:
    113
    Thijs Janzen
    Oct 19, 2008
  5. Mellow Crow
    Replies:
    6
    Views:
    420
    Richard Cornford
    Nov 4, 2005
Loading...

Share This Page