From e353fb75242d3b51d524af10dfe58883ced36f3c Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Sun, 13 Dec 2020 19:16:51 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20Improved=20pipe()=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpmon/Singletons/Shell.swift | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/phpmon/Singletons/Shell.swift b/phpmon/Singletons/Shell.swift index 9ed509c..f08b6f2 100644 --- a/phpmon/Singletons/Shell.swift +++ b/phpmon/Singletons/Shell.swift @@ -34,20 +34,16 @@ class Shell { */ public func pipe(_ command: String, shell: String = "/bin/sh") -> String { let task = Process() + let pipe = Pipe() + task.launchPath = shell task.arguments = ["--login", "-c", command] - - let pipe = Pipe() task.standardOutput = pipe task.launch() - - let data = pipe.fileHandleForReading.readDataToEndOfFile() - - let output: String = NSString( - data: data, - encoding: String.Encoding.utf8.rawValue - )! as String - return output + return String( + data: pipe.fileHandleForReading.readDataToEndOfFile(), + encoding: .utf8 + )! } }