File tree Expand file tree Collapse file tree 4 files changed +32
-4
lines changed Expand file tree Collapse file tree 4 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -94,6 +94,10 @@ public struct Configuration: Sendable {
9494 var _spawnResult = spawnResultBox!. take ( ) !
9595
9696 let execution = _spawnResult. execution
97+ defer {
98+ // Close process file descriptor now we finished monitoring
99+ execution. processIdentifier. close ( )
100+ }
97101
98102 return try await withAsyncTaskCleanupHandler {
99103 let inputIO = _spawnResult. inputWriteEnd ( )
@@ -118,9 +122,6 @@ public struct Configuration: Sendable {
118122 for: execution. processIdentifier
119123 )
120124
121- // Close process file descriptor now we finished monitoring
122- execution. processIdentifier. close ( )
123-
124125 return ExecutionResult (
125126 terminationStatus: terminationStatus,
126127 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 @@ -168,6 +168,15 @@ extension InputProtocol where Self == FileDescriptorInput {
168168 closeAfterSpawningProcess: closeAfterSpawningProcess
169169 )
170170 }
171+
172+ /// Create a Subprocess input that reads from the standard input of
173+ /// current process. The file descriptor should not be closed afterwards.
174+ public static var standardInput : Self {
175+ return Self . fileDescriptor (
176+ . standardInput,
177+ closeAfterSpawningProcess: false
178+ )
179+ }
171180}
172181
173182extension InputProtocol {
Original file line number Diff line number Diff line change @@ -218,6 +218,24 @@ extension OutputProtocol where Self == FileDescriptorOutput {
218218 ) -> Self {
219219 return . init( fileDescriptor: fd, closeAfterSpawningProcess: closeAfterSpawningProcess)
220220 }
221+
222+ /// Create a Subprocess output that writes output to the standard output of
223+ /// current process. The file descriptor should not be closed afterwards.
224+ public static var standardOutput : Self {
225+ return Self . fileDescriptor (
226+ . standardOutput,
227+ closeAfterSpawningProcess: false
228+ )
229+ }
230+
231+ /// Create a Subprocess output that write output to the standard error of
232+ /// current process. The file descriptor should not be closed afterwards.
233+ public static var standardError : Self {
234+ return Self . fileDescriptor (
235+ . standardError,
236+ closeAfterSpawningProcess: false
237+ )
238+ }
221239}
222240
223241extension OutputProtocol where Self == StringOutput < UTF8 > {
You can’t perform that action at this time.
0 commit comments