Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Sources/Subprocess/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ public struct Configuration: Sendable {
var _spawnResult = spawnResultBox!.take()!

let execution = _spawnResult.execution
defer {
// Close process file descriptor now we finished monitoring
execution.processIdentifier.close()
}

return try await withAsyncTaskCleanupHandler {
let inputIO = _spawnResult.inputWriteEnd()
Expand All @@ -127,9 +131,6 @@ public struct Configuration: Sendable {
for: execution.processIdentifier
)

// Close process file descriptor now we finished monitoring
execution.processIdentifier.close()

return ExecutionResult(
terminationStatus: terminationStatus,
value: try result.get()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Subprocess/IO/AsyncIO+Linux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ final class AsyncIO: Sendable {
)
if rc != 0 {
_registration.withLock { storage in
storage.removeValue(forKey: fileDescriptor.rawValue)
_ = storage.removeValue(forKey: fileDescriptor.rawValue)
}

let capturedError = errno
Expand Down
11 changes: 11 additions & 0 deletions Sources/Subprocess/IO/Input.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@ extension InputProtocol where Self == FileDescriptorInput {
closeAfterSpawningProcess: closeAfterSpawningProcess
)
}

/// Create a Subprocess input that reads from the standard input of
/// current process.
///
/// The file descriptor isn't closed afterwards.
public static var standardInput: Self {
return Self.fileDescriptor(
.standardInput,
closeAfterSpawningProcess: false
)
}
}

extension InputProtocol {
Expand Down
22 changes: 22 additions & 0 deletions Sources/Subprocess/IO/Output.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,28 @@ extension OutputProtocol where Self == FileDescriptorOutput {
) -> Self {
return .init(fileDescriptor: fd, closeAfterSpawningProcess: closeAfterSpawningProcess)
}

/// Create a Subprocess output that writes output to the standard output of
/// current process.
///
/// The file descriptor isn't closed afterwards.
public static var standardOutput: Self {
return Self.fileDescriptor(
.standardOutput,
closeAfterSpawningProcess: false
)
}

/// Create a Subprocess output that write output to the standard error of
/// current process.
///
/// The file descriptor isn't closed afterwards.
public static var standardError: Self {
return Self.fileDescriptor(
.standardError,
closeAfterSpawningProcess: false
)
}
}

extension OutputProtocol where Self == StringOutput<UTF8> {
Expand Down