1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 20:10:08 +02:00

👌 Improved pipe() method

This commit is contained in:
2020-12-13 19:16:51 +01:00
parent 458868d051
commit e353fb7524

View File

@ -34,20 +34,16 @@ class Shell {
*/ */
public func pipe(_ command: String, shell: String = "/bin/sh") -> String { public func pipe(_ command: String, shell: String = "/bin/sh") -> String {
let task = Process() let task = Process()
let pipe = Pipe()
task.launchPath = shell task.launchPath = shell
task.arguments = ["--login", "-c", command] task.arguments = ["--login", "-c", command]
let pipe = Pipe()
task.standardOutput = pipe task.standardOutput = pipe
task.launch() 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
)!
} }
} }