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?
Process#getInputStreamand read from it, which is the process's out, which is demonstrated within this answerInputStream#readis 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...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.