Skip to content

Commit 4ebf258

Browse files
authored
Merge pull request JohnSundell#23 from SteveBarnegren/dont_close_standard_file_handlers
Don't close standard file handlers
2 parents 69fd5fe + 40d9a26 commit 4ebf258

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Sources/ShellOut.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,13 @@ private extension Process {
394394

395395
waitUntilExit()
396396

397-
outputHandle?.closeFile()
398-
errorHandle?.closeFile()
397+
if let handle = outputHandle, !handle.isStandard {
398+
handle.closeFile()
399+
}
400+
401+
if let handle = errorHandle, !handle.isStandard {
402+
handle.closeFile()
403+
}
399404

400405
#if !os(Linux)
401406
outputPipe.fileHandleForReading.readabilityHandler = nil
@@ -418,6 +423,14 @@ private extension Process {
418423
}
419424
}
420425

426+
private extension FileHandle {
427+
var isStandard: Bool {
428+
return self === FileHandle.standardOutput ||
429+
self === FileHandle.standardError ||
430+
self === FileHandle.standardInput
431+
}
432+
}
433+
421434
private extension Data {
422435
func shellOutput() -> String {
423436
guard let output = String(data: self, encoding: .utf8) else {

0 commit comments

Comments
 (0)