From 569841cc7ffc39a908f17b6e3014bf9162994f21 Mon Sep 17 00:00:00 2001 From: Steve Barnegren Date: Sat, 18 Nov 2017 23:11:00 +0000 Subject: [PATCH 1/2] Don't close standard handles --- Sources/ShellOut.swift | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Sources/ShellOut.swift b/Sources/ShellOut.swift index 4e1624a..a9f49a6 100644 --- a/Sources/ShellOut.swift +++ b/Sources/ShellOut.swift @@ -380,9 +380,14 @@ private extension Process { #endif 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 @@ -396,17 +401,25 @@ private extension Process { outputData: outputData ) } - + return outputData.shellOutput() } } +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 { return "" } - + guard !output.hasSuffix("\n") else { let endIndex = output.index(before: output.endIndex) return String(output[.. Date: Sun, 19 Nov 2017 00:56:49 +0000 Subject: [PATCH 2/2] Remove whitespace --- Sources/ShellOut.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/ShellOut.swift b/Sources/ShellOut.swift index a9f49a6..becab55 100644 --- a/Sources/ShellOut.swift +++ b/Sources/ShellOut.swift @@ -380,11 +380,11 @@ private extension Process { #endif waitUntilExit() - + if let handle = outputHandle, !handle.isStandard { handle.closeFile() } - + if let handle = errorHandle, !handle.isStandard { handle.closeFile() } @@ -401,7 +401,7 @@ private extension Process { outputData: outputData ) } - + return outputData.shellOutput() } } @@ -419,7 +419,7 @@ private extension Data { guard let output = String(data: self, encoding: .utf8) else { return "" } - + guard !output.hasSuffix("\n") else { let endIndex = output.index(before: output.endIndex) return String(output[..