0

I have a process builder that initiates a process that "tails" new line added to a really big log file.

Right now I'm

ProcessBuilder m_builder = new ProcessBuilder(fullCmdList); m_builder.redirectOutput(ProcessBuilder.Redirect.INHERIT); m_builder.redirectError(ProcessBuilder.Redirect.INHERIT); Process m = m_builder.start(); m.waitFor(); 

redirecting output to stdout. Instead I'd like to detect when the process in question writes anything (I don't care what it writes) and trigger certain events.

Is there a way I can detect when a process writes it's first bit/byte to it's output stream when invoked via process builder?

4
  • 2
    Use Process#getInputStream and read from it, which is the process's out, which is demonstrated within this answer Commented Mar 25, 2015 at 1:30
  • I don't want to read the entire length of the stream. I'd like to cut and run the moment the first character is written Commented Mar 25, 2015 at 1:36
  • Then don't use a while-loop InputStream#read is a blocking call, it will wait until there is something to read. The danger is, some process's will hang if you don't read there output... Commented Mar 25, 2015 at 1:37
  • Using Process.getInputStream() doesn't commit you to reading to the end of it, but starting any process that produces output does commit you to that. You can trigger your actions when the first data arrives, but you still have to read to end of stream: otherwise the process is liable to block. Commented Mar 25, 2015 at 2:13

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.