Task
Execute a system command and get its output into the program. The output may be stored in any kind of collection (array, list, etc.).




Related task
  Execute a system command


import Foundation
 
let process = Process()
 
process.launchPath = "/usr/bin/env"
process.arguments = ["pwd"]
 
let pipe = Pipe()
process.standardOutput = pipe
 
process.launch()
 
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String.init(data: data, encoding: String.Encoding.utf8)
 
print(output!)