I am trying to run a terminal command in a Mac app that I am developing. The terminal command is:
sudo sysctl -w net.inet.tcp.delayed_ack=0
I have tried using NSTask but it seems that I am doing something wrong every time.
I just want to run this command and print the output. Thank you for your attention.
PS. here is what my current code looks like (thanks to your replies):
let task = NSTask()
task.launchPath = "/usr/sbin/sysctl"
task.arguments = ["-w", "net.inet.tcp.delayed_ack=0"]
let pipe = NSPipe()
task.standardOutput = pipe
task.standardError = pipe
task.launch()
task.waitUntilExit()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output: String = NSString(data: data, encoding: NSUTF8StringEncoding) as! String
I receive the following message in the output:
net.inet.tcp.delayed_ack: 3
sysctl: net.inet.tcp.delayed_ack=0: Operation not permitted