Input / output to an external process

Discussion in 'Java' started by =?ISO-8859-1?Q?Reidar_=D8ksnevad?=, Jul 28, 2006.

  1. Hi,

    I have a program that uses the ProcessBuilder class to invoke an external
    program (kpsewhich). This works fine when I only want to pass an argument
    to the program, and return one line of output:

    <code>
    kpseProcess = new ProcessBuilder("kpsewhich", filename).start();
    kpseReader = new BufferedReader(new InputStreamReader(
    kpseProcess.getInputStream()));
    kpseProcess.waitFor(); // wait for process to end

    String output = kpseReader.readLine();
    </code>

    The problem with this solution is that kpsewhich has an "interactive"
    mode, which allows the caller to keep the process running, and simply pass
    file names through its input stream.

    I would therefore like to have the process running in a separate thread,
    and send input whenever I need to. I have been trying to do this using the
    process' output stream, kpseProcess.getOutputStream(), but with no luck.

    Can anyone point me in the right direction?

    Regards,
    Reidar ├śksnevad
     
    =?ISO-8859-1?Q?Reidar_=D8ksnevad?=, Jul 28, 2006
    #1
    1. Advertisements

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. rtm
    Replies:
    0
    Views:
    928
  2. Guifre
    Replies:
    1
    Views:
    509
    Thomas Weidenfeller
    May 24, 2005
  3. W. D. Allen Sr.

    Simple HTML User Input and Process Output

    W. D. Allen Sr., Sep 12, 2005, in forum: HTML
    Replies:
    2
    Views:
    694
    Toby Inkster
    Sep 12, 2005
  4. Hoegje
    Replies:
    2
    Views:
    22,835
    Gianni Mariani
    Dec 5, 2003
  5. Scott Allen
    Replies:
    8
    Views:
    11,405
    Scott Allen
    May 2, 2004
  6. Brian Elmegaard
    Replies:
    2
    Views:
    1,145
    Robert Amesz
    Sep 10, 2003
  7. reid
    Replies:
    4
    Views:
    932
  8. Mellow Crow
    Replies:
    6
    Views:
    695
    Richard Cornford
    Nov 4, 2005
Loading...