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 {
94
94
var _spawnResult = spawnResultBox!. take ( ) !
95
95
96
96
let execution = _spawnResult. execution
97
+ defer {
98
+ // Close process file descriptor now we finished monitoring
99
+ execution. processIdentifier. close ( )
100
+ }
97
101
98
102
return try await withAsyncTaskCleanupHandler {
99
103
let inputIO = _spawnResult. inputWriteEnd ( )
@@ -118,9 +122,6 @@ public struct Configuration: Sendable {
118
122
for: execution. processIdentifier
119
123
)
120
124
121
- // Close process file descriptor now we finished monitoring
122
- execution. processIdentifier. close ( )
123
-
124
125
return ExecutionResult (
125
126
terminationStatus: terminationStatus,
126
127
value: try result. get ( )
Original file line number Diff line number Diff line change @@ -288,7 +288,7 @@ final class AsyncIO: Sendable {
288
288
)
289
289
if rc != 0 {
290
290
_registration. withLock { storage in
291
- storage. removeValue ( forKey: fileDescriptor. rawValue)
291
+ _ = storage. removeValue ( forKey: fileDescriptor. rawValue)
292
292
}
293
293
294
294
let capturedError = errno
Original file line number Diff line number Diff line change @@ -168,6 +168,15 @@ extension InputProtocol where Self == FileDescriptorInput {
168
168
closeAfterSpawningProcess: closeAfterSpawningProcess
169
169
)
170
170
}
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
+ }
171
180
}
172
181
173
182
extension InputProtocol {
Original file line number Diff line number Diff line change @@ -218,6 +218,24 @@ extension OutputProtocol where Self == FileDescriptorOutput {
218
218
) -> Self {
219
219
return . init( fileDescriptor: fd, closeAfterSpawningProcess: closeAfterSpawningProcess)
220
220
}
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
+ }
221
239
}
222
240
223
241
extension OutputProtocol where Self == StringOutput < UTF8 > {
You can’t perform that action at this time.
0 commit comments