Skip to content

Commit 5f65c94

Browse files
committed
Fix shutdown of output stream threads
1 parent 95f1657 commit 5f65c94

File tree

1 file changed

+14
-20
lines changed
  • src/main/java/org/mcphackers/mcp/tools

1 file changed

+14
-20
lines changed

src/main/java/org/mcphackers/mcp/tools/Util.java

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.mcphackers.mcp.tools;
22

3-
import java.awt.*;
3+
import java.awt.Desktop;
4+
import java.awt.Toolkit;
45
import java.awt.datatransfer.StringSelection;
56
import java.io.BufferedInputStream;
67
import java.io.BufferedReader;
@@ -37,41 +38,34 @@ public static int runCommand(String[] cmd, Path dir, boolean killOnShutdown) thr
3738
BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
3839
Thread stderr = new Thread(()-> {
3940
String line;
40-
while (true) {
41-
try {
42-
line = err.readLine();
43-
if(line != null) {
44-
System.out.println("Minecraft STDERR: " + line);
45-
}
46-
} catch (IOException ignored) {
47-
// we don't really care what happens here
41+
try {
42+
while((line = err.readLine()) != null) {
43+
System.out.println("Minecraft STDERR: " + line);
4844
}
45+
} catch (IOException ignored) {
46+
// we don't really care what happens here
4947
}
5048

5149
});
5250
Thread stdout = new Thread(()-> {
5351
String line;
54-
while (true) {
55-
try {
56-
line = in.readLine();
57-
if(line != null) {
58-
System.out.println( line);
59-
}
60-
} catch (IOException ignored) {
61-
// we don't really care what happens here
52+
try {
53+
while((line = in.readLine()) != null) {
54+
System.out.println(line);
6255
}
56+
} catch (IOException ignored) {
57+
// we don't really care what happens here
6358
}
64-
6559
});
60+
stdout.start();
61+
stderr.start();
6662
try {
6763
proc.waitFor();
6864
} catch (InterruptedException e) {
6965
throw new RuntimeException("thread interrupted while runCommand was waiting for a process to finish", e );
7066
}
7167
in.close();
7268
err.close();
73-
stderr.interrupt();
74-
stdout.interrupt();
7569

7670
if (killOnShutdown) {
7771
Runtime.getRuntime().removeShutdownHook(hook);

0 commit comments

Comments
 (0)