From cb62ae23acd1f7350efaaf4e47c5ebfe8e8c9480 Mon Sep 17 00:00:00 2001 From: "Sven A. Schmidt" Date: Fri, 25 Aug 2023 15:24:54 +0200 Subject: [PATCH] More fixed proposed by Gwynne --- Sources/ShellOut.swift | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/Sources/ShellOut.swift b/Sources/ShellOut.swift index 32de09c..f62c227 100644 --- a/Sources/ShellOut.swift +++ b/Sources/ShellOut.swift @@ -434,13 +434,8 @@ private extension Process { waitUntilExit() - if let handle = outputHandle, !handle.isStandard { - handle.closeFile() - } - - if let handle = errorHandle, !handle.isStandard { - handle.closeFile() - } + outputHandle?.closeFile() + errorHandle?.closeFile() outputPipe.fileHandleForReading.readabilityHandler = nil errorPipe.fileHandleForReading.readabilityHandler = nil @@ -461,23 +456,12 @@ 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 { - return "" - } + let output = String(decoding: self, as: UTF8.self) guard !output.hasSuffix("\n") else { - let endIndex = output.index(before: output.endIndex) - return String(output[..