Skip to content

Commit

Permalink
Merge pull request #23 from SteveBarnegren/dont_close_standard_file_h…
Browse files Browse the repository at this point in the history
…andlers

Don't close standard file handlers
  • Loading branch information
JohnSundell authored Dec 12, 2019
2 parents 69fd5fe + 40d9a26 commit 4ebf258
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Sources/ShellOut.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 4ebf258

Please sign in to comment.