У меня есть следующий код и я хочу экспортировать результат self.logger.string += line
в файл.Как это сделать?
func syncShellExec(path: String, args: [String] = []) {
//let script = [path!]
let process = Process()
process.launchPath = "/bin/bash"
process.arguments = [path] + args
let outputPipe = Pipe()
let filelHandler = outputPipe.fileHandleForReading
process.standardOutput = outputPipe
filelHandler.readabilityHandler = { pipe in
let data = pipe.availableData
if let line = String(data: data, encoding: .utf8) {
// Update your view with the new text here
// Bounce back to the main thread to update the UI
DispatchQueue.main.async {
self.logger.string += line
}
} else {
print("Error decoding data: \(data.base64EncodedString())")
}
}
process.launch()
process.waitUntilExit()
filelHandler.readabilityHandler = nil
//self.loggerScroll.flashScrollers()
}