Avatar
omochimetaru 4/5/2018 9:13 PM
@swiftbot import Foundation func exec(_ cmd: [String]) -> String { let process = Process() process.executableURL = URL(fileURLWithPath: cmd[0]) let pipe = Pipe() process.standardOutput = pipe process.arguments = Array(cmd[1...]) try! process.run() let handle = pipe.fileHandleForReading let data = handle.readDataToEndOfFile() let str = String(data: data, encoding: .utf8) ?? "<binary>" return str } print(exec(["/bin/ls", "-al"]))