diff --git a/Sources/ShellOut.swift b/Sources/ShellOut.swift index b015102..4a18a1f 100644 --- a/Sources/ShellOut.swift +++ b/Sources/ShellOut.swift @@ -394,8 +394,13 @@ private extension Process { waitUntilExit() - outputHandle?.closeFile() - errorHandle?.closeFile() + if let handle = outputHandle, !handle.isStandard { + handle.closeFile() + } + + if let handle = errorHandle, !handle.isStandard { + handle.closeFile() + } #if !os(Linux) outputPipe.fileHandleForReading.readabilityHandler = nil @@ -418,6 +423,14 @@ private extension Process { } } +private extension FileHandle { + var isStandard: Bool { + return self === FileHandle.standardOutput || + self === FileHandle.standardError || + self === FileHandle.standardInput + } +} + private extension Data { func shellOutput() -> String { guard let output = String(data: self, encoding: .utf8) else {