Skip to content

Commit 17f93a4

Browse files
authored
Merge pull request #14 from devchat-ai/fix-topic-list
Fix subprocess waitFor blocking
2 parents ca2bf05 + 8a0b284 commit 17f93a4

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ bin/
3939
.vscode/
4040

4141
### Mac OS ###
42-
.DS_Store
42+
.DS_Store
43+
tmp/

src/main/kotlin/ai/devchat/cli/DevChatWrapper.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,19 @@ class DevChatWrapper {
4545
return try {
4646
Log.info("Executing command: " + java.lang.String.join(" ", pb.command()))
4747
val process = pb.start()
48-
val exitCode = process.waitFor()
48+
val text = process.inputStream.bufferedReader().use(BufferedReader::readText)
49+
val errors = process.errorStream.bufferedReader().use(BufferedReader::readText)
50+
process.waitFor()
51+
val exitCode = process.exitValue()
52+
4953
if (exitCode != 0) {
50-
val error = readOutput(process.errorStream)
51-
Log.error("Failed to execute command: $commands Exit Code: $exitCode Error: $error")
54+
Log.error("Failed to execute command: $commands Exit Code: $exitCode Error: $errors")
5255
throw RuntimeException(
53-
"Failed to execute command: $commands Exit Code: $exitCode Error: $error"
56+
"Failed to execute command: $commands Exit Code: $exitCode Error: $errors"
5457
)
58+
} else {
59+
text
5560
}
56-
readOutput(process.inputStream)
5761
} catch (e: IOException) {
5862
Log.error("Failed to execute command: $commands")
5963
throw RuntimeException("Failed to execute command: $commands", e)

0 commit comments

Comments
 (0)