35 NSTask
Each application that you have created is a bundle, a directory which OS X displays to the user as a single file. Somewhere down in that directory is an executable file. To run an executable on a Unix machine, like your Mac, a process is forked and the new process executes the code in that file. Many executables are command-line tools, and some are quite handy. In this chapter, you will learn how to run a command-line tool from your Cocoa application using NSTask.
NSTask is an easy-to-use wrapper for the Unix functions fork() and exec(). You give NSTask a path to an executable and launch it. Many processes read data from standard-in and write to standard-out and standard-error. Your application can use NSTask to attach ...
Get Cocoa Programming for OS X: The Big Nerd Ranch Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.