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. 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. rtm
    Replies:
    0
    Views:
    796
  2. Guifre
    Replies:
    1
    Views:
    415
    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:
    622
    Toby Inkster
    Sep 12, 2005
  4. Brian Elmegaard
    Replies:
    2
    Views:
    986
    Robert Amesz
    Sep 10, 2003
  5. reid
    Replies:
    4
    Views:
    672
Loading...

Share This Page