refactor(macos): centralize process pipe draining

This commit is contained in:
Peter Steinberger
2026-01-17 08:53:03 +00:00
parent 1002c74d9c
commit 869ef0c5ba
7 changed files with 20 additions and 24 deletions

View File

@@ -16,12 +16,7 @@ enum Launchctl {
process.standardOutput = pipe
process.standardError = pipe
do {
try process.run()
// Read pipe output BEFORE waitUntilExit to avoid deadlock.
// If the process writes enough to fill the pipe buffer (~64KB),
// it will block until someone reads. Reading first prevents this.
let data = pipe.fileHandleForReading.readToEndSafely()
process.waitUntilExit()
let data = try process.runAndReadToEnd(from: pipe)
let output = String(data: data, encoding: .utf8) ?? ""
return Result(status: process.terminationStatus, output: output)
} catch {