Skip to content

Commit

Permalink
don't need new thread
Browse files Browse the repository at this point in the history
  • Loading branch information
exFalso committed Jul 25, 2014
1 parent 4ab91e3 commit ee30f86
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions src/main/java/com/prezi/haxe/gradle/CommandExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,10 @@ public static void execute(List<String> cmd, File dir, ExecutionResultHandler ha
ProcessBuilder builder = new ProcessBuilder(cmd);
builder.redirectErrorStream(true);
builder.directory(dir);
final Process process = builder.start();
final ByteArrayOutputStream bytes = new ByteArrayOutputStream();

final Semaphore stdoutReaderSema = new Semaphore(0);
Thread stdoutReader = new Thread() {
public void run() {
try {
ByteStreams.copy(process.getInputStream(), bytes);
} catch (IOException exception) {
logger.error("Exception while reading from subprocess " + process + ": " + exception);
}
stdoutReaderSema.release();
}
};
stdoutReader.start();
Process process = builder.start();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
ByteStreams.copy(process.getInputStream(), bytes);
process.waitFor();
stdoutReaderSema.acquire();

String output = bytes.toString(Charsets.UTF_8.name());

Expand Down

0 comments on commit ee30f86

Please sign in to comment.