Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #27743

a question about using ProcessBuilder to call external command

Newsgroups comp.lang.java.programmer
Date 2014-03-12 13:06 -0700
Message-ID <8f4aa46a-16f4-4b36-a951-7e8eda1692db@googlegroups.com> (permalink)
Subject a question about using ProcessBuilder to call external command
From zyng <xsli2@yahoo.com>

Show all headers | View raw


Hi:

I am using the following code to call a system command

final ProcessBuilder processBuilder = new ProcessBuilder(new String[]{"/bin/sh", "-c", the_command_and_arguments});

final Process processRunSysCmd = processBuilder.start();//start a new process -- a child process


I have learned that I need to drain the output of the external command (input stream to the parent process -- the java program) in case that it has too much output and the buffer is saturated. In that case, the program will hang.

But when I think deeper, I am puzzled: there are two processes running now(one is the one i called "parent process", another is the child process). Since each one is single threaded, may I say there are two threads right now?!

So if I don't drain the output of the child process, and too much output and buffer saturated, the parent process will hang?! Will the child process hang too? Or both processes hang? Since they are two threads, so one thread cause another thread hang?

Thank you.

Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

a question about using ProcessBuilder to call external command zyng <xsli2@yahoo.com> - 2014-03-12 13:06 -0700
  Re: a question about using ProcessBuilder to call external command zyng <xsli2@yahoo.com> - 2014-03-12 13:10 -0700
    Re: a question about using ProcessBuilder to call external command Roedy Green <see_website@mindprod.com.invalid> - 2014-03-17 03:02 -0700
  Re: a question about using ProcessBuilder to call external command Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-03-12 16:36 -0400
  Re: a question about using ProcessBuilder to call external command Roedy Green <see_website@mindprod.com.invalid> - 2014-03-16 01:03 -0700

csiph-web