File tree Expand file tree Collapse file tree 4 files changed +38
-4
lines changed Expand file tree Collapse file tree 4 files changed +38
-4
lines changed Original file line number Diff line number Diff line change @@ -103,6 +103,10 @@ public struct Configuration: Sendable {
103103 var _spawnResult = spawnResultBox!. take ( ) !
104104
105105 let execution = _spawnResult. execution
106+ defer {
107+ // Close process file descriptor now we finished monitoring
108+ execution. processIdentifier. close ( )
109+ }
106110
107111 return try await withAsyncTaskCleanupHandler {
108112 let inputIO = _spawnResult. inputWriteEnd ( )
@@ -127,9 +131,6 @@ public struct Configuration: Sendable {
127131 for: execution. processIdentifier
128132 )
129133
130- // Close process file descriptor now we finished monitoring
131- execution. processIdentifier. close ( )
132-
133134 return ExecutionResult (
134135 terminationStatus: terminationStatus,
135136 value: try result. get ( )
Original file line number Diff line number Diff line change @@ -288,7 +288,7 @@ final class AsyncIO: Sendable {
288288 )
289289 if rc != 0 {
290290 _registration. withLock { storage in
291- storage. removeValue ( forKey: fileDescriptor. rawValue)
291+ _ = storage. removeValue ( forKey: fileDescriptor. rawValue)
292292 }
293293
294294 let capturedError = errno
Original file line number Diff line number Diff line change @@ -179,6 +179,17 @@ extension InputProtocol where Self == FileDescriptorInput {
179179 closeAfterSpawningProcess: closeAfterSpawningProcess
180180 )
181181 }
182+
183+ /// Create a Subprocess input that reads from the standard input of
184+ /// current process.
185+ ///
186+ /// The file descriptor isn't closed afterwards.
187+ public static var standardInput : Self {
188+ return Self . fileDescriptor (
189+ . standardInput,
190+ closeAfterSpawningProcess: false
191+ )
192+ }
182193}
183194
184195extension InputProtocol {
Original file line number Diff line number Diff line change @@ -231,6 +231,28 @@ extension OutputProtocol where Self == FileDescriptorOutput {
231231 ) -> Self {
232232 return . init( fileDescriptor: fd, closeAfterSpawningProcess: closeAfterSpawningProcess)
233233 }
234+
235+ /// Create a Subprocess output that writes output to the standard output of
236+ /// current process.
237+ ///
238+ /// The file descriptor isn't closed afterwards.
239+ public static var standardOutput : Self {
240+ return Self . fileDescriptor (
241+ . standardOutput,
242+ closeAfterSpawningProcess: false
243+ )
244+ }
245+
246+ /// Create a Subprocess output that write output to the standard error of
247+ /// current process.
248+ ///
249+ /// The file descriptor isn't closed afterwards.
250+ public static var standardError : Self {
251+ return Self . fileDescriptor (
252+ . standardError,
253+ closeAfterSpawningProcess: false
254+ )
255+ }
234256}
235257
236258extension OutputProtocol where Self == StringOutput < UTF8 > {
You can’t perform that action at this time.
0 commit comments