This is probably a stupid question, but how can I execute a shell command from my Cocoa app?
I have the command as a string "command", but can easily manipulate data as needed.
There is no need to get a returned output value.
This is probably a stupid question, but how can I execute a shell command from my Cocoa app?
I have the command as a string "command", but can easily manipulate data as needed.
There is no need to get a returned output value.
If you just want to run something and don't care about the output or return code (for example, you want to touch a file), you can just do
Easy as that.
NSTask is pretty easy to do this with. For a synchronous call, you can use something like this fragment:
The
-waitUntilExit
call makes sure it finishes before proceeding. If the task can be asynchronous, you can remove that call and just let the NSTask do it's thing.NSTask