I'm trying to get a separated standardError output and standardOutput string but I also need the full string. Following code will explain my case
combined/full string:
let task = Process()
task.launchPath = "/usr/sbin/killall"
task.arguments = ["Dock"]
let pipe = Pipe()
task.standardOutput = pipe
task.standardError = pipe
task.launch()
task.waitUntilExit()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let fulloutput: String = NSString(data: data, encoding: String.Encoding.utf8.rawValue) as! String
print(fulloutput)
Separated strings:
let task = Process()
task.launchPath = "/usr/sbin/killall"
task.arguments = ["Dock"]
let pipe = Pipe()
let errorpipe = Pipe()
task.standardOutput = pipe
task.standardError = errorpipe
task.launch()
task.waitUntilExit()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let errordata = pipe.fileHandleForReading.readDataToEndOfFile()
let output: String = NSString(data: data, encoding: String.Encoding.utf8.rawValue) as! String
let erroroutput: String = NSString(data: data, encoding: String.Encoding.utf8.rawValue) as! String
print(output)
print(erroroutput)
How do I combine these 2 so I get an output like this without running the command twice?:
print(output)
print(erroroutput)
print(fulloutput)
Thanks!