Skip to content

Commit 85061a0

Browse files
authored
Fix call Bindiff hanging (#39)
1 parent 4bf32a9 commit 85061a0

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

src/main/java/bindiffhelper/BinDiffHelperPlugin.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -194,26 +194,30 @@ public void callBinDiff(DomainFile df, Consumer<File[]> callback)
194194
Msg.debug(this, "printing BD output for cmd: " + Arrays.toString(cmd));
195195
Process p = null;
196196
try {
197-
p = Runtime.getRuntime().exec(cmd);
198-
var i = new BufferedReader(new InputStreamReader(p.getInputStream()));
199-
var stderr = p.getErrorStream();
200-
while (!p.waitFor(1, TimeUnit.SECONDS)) {
201-
// Empty stderr buffer
202-
stderr.skip(stderr.available());
203-
204-
while (true)
205-
{
206-
String line = i.readLine();
207-
208-
if (line == null)
209-
break;
210-
211-
Msg.debug(this, ">" + line);
197+
ProcessBuilder pb = new ProcessBuilder(cmd);
198+
pb.redirectErrorStream(true);
199+
p = pb.start();
200+
201+
Process finalP = p;
202+
Thread outputReader = new Thread(() -> {
203+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(finalP.getInputStream()))) {
204+
String line;
205+
while ((line = reader.readLine()) != null) {
206+
Msg.debug(this, "> " + line);
207+
}
208+
} catch (IOException e) {
209+
e.printStackTrace();
212210
}
213-
211+
});
212+
outputReader.start();
213+
214+
while (!p.waitFor(1, TimeUnit.SECONDS)) {
214215
d.checkCanceled();
215216
}
216-
217+
218+
outputReader.join();
219+
int exitCode = p.exitValue();
220+
Msg.debug(this, "Process exited with code: " + exitCode);
217221
Msg.debug(this, "end of output");
218222

219223
} catch (IOException | InterruptedException e) {

0 commit comments

Comments
 (0)