Skip to content

Commit 2b31636

Browse files
author
Paul Marbach
committed
use threads to ensure that .use doesn't block
1 parent 19ee4ce commit 2b31636

File tree

1 file changed

+8
-2
lines changed
  • shared/src/main/kotlin/org/javacs/kt/util

1 file changed

+8
-2
lines changed

shared/src/main/kotlin/org/javacs/kt/util/Utils.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@ fun execAndReadStdoutAndStderr(shellCommand: String, directory: Path): Pair<Stri
1717
val process = Runtime.getRuntime().exec(shellCommand, null, directory.toFile())
1818
val stdout = process.inputStream
1919
val stderr = process.errorStream
20-
val output = stdout.bufferedReader().use { it.readText() }
21-
val errors = stderr.bufferedReader().use { it.readText() }
20+
var output = ""
21+
var errors = ""
22+
val outputThread = Thread { stdout.bufferedReader().use { output += it.readText() } }
23+
val errorsThread = Thread { stderr.bufferedReader().use { errors += it.readText() } }
24+
outputThread.start()
25+
errorsThread.start()
26+
outputThread.join()
27+
errorsThread.join()
2228
return Pair(output, errors)
2329
}
2430

0 commit comments

Comments
 (0)