Skip to content

Commit cb62ae2

Browse files
committed
More fixed proposed by Gwynne
1 parent 3aafd16 commit cb62ae2

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

Sources/ShellOut.swift

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -434,13 +434,8 @@ private extension Process {
434434

435435
waitUntilExit()
436436

437-
if let handle = outputHandle, !handle.isStandard {
438-
handle.closeFile()
439-
}
440-
441-
if let handle = errorHandle, !handle.isStandard {
442-
handle.closeFile()
443-
}
437+
outputHandle?.closeFile()
438+
errorHandle?.closeFile()
444439

445440
outputPipe.fileHandleForReading.readabilityHandler = nil
446441
errorPipe.fileHandleForReading.readabilityHandler = nil
@@ -461,23 +456,12 @@ private extension Process {
461456
}
462457
}
463458

464-
private extension FileHandle {
465-
var isStandard: Bool {
466-
return self === FileHandle.standardOutput ||
467-
self === FileHandle.standardError ||
468-
self === FileHandle.standardInput
469-
}
470-
}
471-
472459
private extension Data {
473460
func shellOutput() -> String {
474-
guard let output = String(data: self, encoding: .utf8) else {
475-
return ""
476-
}
461+
let output = String(decoding: self, as: UTF8.self)
477462

478463
guard !output.hasSuffix("\n") else {
479-
let endIndex = output.index(before: output.endIndex)
480-
return String(output[..<endIndex])
464+
return String(output.dropLast())
481465
}
482466

483467
return output

0 commit comments

Comments
 (0)