@@ -54,6 +54,9 @@ extension ShellExecuting {
54
54
}
55
55
56
56
public struct ShellExecutor : ShellExecuting {
57
+ /// Queue used to concurrently listen to both stdout and stderr
58
+ private let outputQueue = DispatchQueue ( label: " ShellExecutor.outputQueue " , attributes: . concurrent)
59
+
57
60
public init ( ) { }
58
61
59
62
public func execute( _ command: String ,
@@ -98,12 +101,23 @@ public struct ShellExecutor: ShellExecuting {
98
101
task. standardError = stderr
99
102
try task. run ( )
100
103
101
- // Pull out the STDOUT as a string because we'll need that regardless
102
- let stdoutData = stdout. fileHandleForReading. readDataToEndOfFile ( )
103
- let stdoutString = String ( data: stdoutData, encoding: . utf8) !
104
+ let group = DispatchGroup ( )
105
+
106
+ var stdoutString : String !
107
+ var stderrData : Data !
108
+
109
+ outputQueue. async ( group: group, qos: . userInitiated) {
110
+ // Pull out the STDOUT as a string because we'll need that regardless
111
+ let stdoutData = stdout. fileHandleForReading. readDataToEndOfFile ( )
112
+ stdoutString = String ( data: stdoutData, encoding: . utf8) !
113
+ }
114
+
115
+ outputQueue. async ( group: group, qos: . userInitiated) {
116
+ // Read from STDERR to ensure the `Pipe` does not fill up
117
+ stderrData = stderr. fileHandleForReading. readDataToEndOfFile ( )
118
+ }
104
119
105
- // Read from STDERR to ensure the `Pipe` does not fill up
106
- let stderrData = stderr. fileHandleForReading. readDataToEndOfFile ( )
120
+ group. wait ( )
107
121
108
122
task. waitUntilExit ( )
109
123
0 commit comments