<p>I'm trying to make a javafx application which displays the logs from kubernetes. I'm using <code>Runtime.getRuntime().exec</code> to get the output of <code>kubetail servicename</code> in the following way:</p>
<pre><code> Process exec = Runtime.getRuntime().exec(new String[]{&quot;kubetail&quot;, &quot;serviceName&quot;});
        InputStream inputStream = exec.getInputStream();
        int read;
        try {
            while (((read = inputStream.read()) != -1)) {
                System.out.print((char) read);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
</code></pre>
<p>The process starts normally and I see &quot;Will tail 2 pods...&quot;. The problem appears when I make a request on that service and a lot of logs appears. The service returns a report and this report is archived and it is also logged. The report is quite big, 40K characters. The tail somehow hangs in the middle of the logged report and I don't get any more data, but if I send another request, it continues from where it hanged and stops again on the report of the second request.</p>
<p>I tried using buffered reader and also wrapped the inputstream with NIO, but the problem persist. I also tried to use <code>kubectl logs</code> and this works on but I don't have any identification for the line of log (I don't know which pod it belongs to). <code>kubetail</code> gives a stream of logs for all the pods in an application and these are identified by color and by pod name.</p>
<p>Thank you</p>

Vladutu Georgian
<p>You are not consuming the stdout and stderr streams properly, they will cause process output to hang if one fills without you reading it. You could try setting stderr to go to stdout class when using <code>ProcessBuilder</code></p>
<pre><code>ProcessBuilder pb = new ProcessBuilder(new String[]{&quot;kubetail&quot;, &quot;serviceName&quot;});
pb.redirectErrorStream(true);
Process exec = pb.start();
... Your reading code
int rc = exec.waitFor();
</code></pre>
<p>OR: add threads to consume both stdout and stderr streams:</p>
<pre><code>Process exec = Runtime.getRuntime().exec(new String[]{&quot;kubetail&quot;, &quot;serviceName&quot;});        
new Thread(() -&gt; copy(exec.getInputStream(), System.out), &quot;STDOUT&quot;).start();
new Thread(() -&gt; copy(exec.getErrorStream(), System.err), &quot;STDERR&quot;).start();
int rc = exec.waitFor();
</code></pre>
<p>with method:</p>
<pre><code>static void copy(InputStream in, OutputStream out)
{
    try(var autoClose = in; var autoClose2 = out)
    {
        in.transferTo(out);
    }
    catch(IOException io)
    {
        throw new UncheckedIOException(io);
    }
}
</code></pre>
