Closed exFalso closed 9 years ago
If you read the stdout from the same thread that you forked the subprocess from, then your waitFor() call will hang, as nobody's reading the subprocess's stdout until it finishes, meaning a buffer will get full and the processes will deadlock.
The solution is to spawn a new thread that reads the subprocess's stdout while the original thread is blocking on waitFor().
References: http://stackoverflow.com/questions/3807834/processbuilder-gets-stuck-after-getting-an-error http://steveliles.github.io/invoking_processes_from_java.html
If you invoke waitFor()
after reading the contents, it's okay. Have you tried this?
Process process = builder.start();
// remove it from here
// process.waitFor();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
ByteStreams.copy(process.getInputStream(), bytes);
String output = bytes.toString(Charsets.UTF_8.name());
// move it to here
process.waitFor();
Fixes https://github.com/prezi/gradle-haxe-plugin/issues/28