O'Reilly logo

Cocoa in a Nutshell by James Duncan Davidson, Michael Beam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

NSTask — Mac OS X 10.0

Synopsis

This class provides an interface for an application to execute other programs as subprocesses. To create an NSTask, use alloc and init. Before a task can be executed, it must be prepared. By default a task inherits the environment of its parent process, which includes attributes such as the current working directory. To specify what program the task should execute, set the launch path of the program in the task using the method setLaunchPath:. Arguments for the executable are provided in an NSArray through the method setArguments:. If you need to pass data to a task and receive data in return, connect an NSPipe or NSFileHandle object to the executable’s standard input, output, or error using setStandardInput:, setStandardOutput:, and setStandardError:, respectively.

To execute a task, invoke the method launch. NSTask also provides methods for controlling the execution of a task through the methods interrupt, suspend, terminate, and resume.

image with no caption

@interface NSTask : NSObject
                                  // Initializers
   - (id)init;
                                  // Accessor Methods
   - (void)setStandardInput:(id)input;
   - (id)standardInput;
   - (void)setLaunchPath:(NSString *)path;
   - (NSString *)launchPath;
   - (void)setEnvironment:(NSDictionary *)dict;
   - (NSDictionary *)environment;
   - (void)setCurrentDirectoryPath:(NSString *)path;
   - (NSString *)currentDirectoryPath;
   - (void)setStandardOutput ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required