Unable to read InputStream from Java Process (Runtime.getRuntime().exec() or ProcessBuilder)

I realize this is question is old, but I just experienced the same problem. In order to fix this I used this code..

 List<String> commandAndParameters = ...;
 File dir = ...; // CWD for process

 ProcessBuilder builder = new ProcessBuilder();
 builder.redirectErrorStream(true); // This is the important part
 builder.command(commandAndParameters);
 builder.directory(dir);

 Process process = builder.start();

 InputStream is = process.getInputStream();

It appears the process is expecting you to also read from the Error stream. The best fix to this is to merge the input and error stream together.

Update

I didn’t see that you attempted to read from the error stream also. It could just be that you need to merge them manually with redirectErrorStream(true)

Leave a Comment