|
| 1 | +/* NSTask.h |
| 2 | + Copyright (c) 1996-2007, Apple Inc. All rights reserved. |
| 3 | +*/ |
| 4 | + |
| 5 | +#import <Foundation/NSObject.h> |
| 6 | + |
| 7 | +@class NSString, NSArray, NSDictionary; |
| 8 | + |
| 9 | +@interface NSTask : NSObject |
| 10 | + |
| 11 | +// Create an NSTask which can be run at a later time |
| 12 | +// An NSTask can only be run once. Subsequent attempts to |
| 13 | +// run an NSTask will raise. |
| 14 | +// Upon task death a notification will be sent |
| 15 | +// { Name = NSTaskDidTerminateNotification; object = task; } |
| 16 | +// |
| 17 | + |
| 18 | +- (id)init; |
| 19 | + |
| 20 | +// set parameters |
| 21 | +// these methods can only be done before a launch |
| 22 | +- (void)setLaunchPath:(NSString *)path; |
| 23 | +- (void)setArguments:(NSArray *)arguments; |
| 24 | +- (void)setEnvironment:(NSDictionary *)dict; |
| 25 | + // if not set, use current |
| 26 | +- (void)setCurrentDirectoryPath:(NSString *)path; |
| 27 | + // if not set, use current |
| 28 | + |
| 29 | +// set standard I/O channels; may be either an NSFileHandle or an NSPipe |
| 30 | +- (void)setStandardInput:(id)input; |
| 31 | +- (void)setStandardOutput:(id)output; |
| 32 | +- (void)setStandardError:(id)error; |
| 33 | + |
| 34 | +// get parameters |
| 35 | +- (NSString *)launchPath; |
| 36 | +- (NSArray *)arguments; |
| 37 | +- (NSDictionary *)environment; |
| 38 | +- (NSString *)currentDirectoryPath; |
| 39 | + |
| 40 | +// get standard I/O channels; could be either an NSFileHandle or an NSPipe |
| 41 | +- (id)standardInput; |
| 42 | +- (id)standardOutput; |
| 43 | +- (id)standardError; |
| 44 | + |
| 45 | +// actions |
| 46 | +- (void)launch; |
| 47 | + |
| 48 | +- (void)interrupt; // Not always possible. Sends SIGINT. |
| 49 | +- (void)terminate; // Not always possible. Sends SIGTERM. |
| 50 | + |
| 51 | +- (BOOL)suspend; |
| 52 | +- (BOOL)resume; |
| 53 | + |
| 54 | +// status |
| 55 | +- (int)processIdentifier; |
| 56 | +- (BOOL)isRunning; |
| 57 | + |
| 58 | +- (int)terminationStatus; |
| 59 | + |
| 60 | +@end |
| 61 | + |
| 62 | +@interface NSTask (NSTaskConveniences) |
| 63 | + |
| 64 | ++ (NSTask *)launchedTaskWithLaunchPath:(NSString *)path arguments:(NSArray *)arguments; |
| 65 | + // convenience; create and launch |
| 66 | + |
| 67 | +- (void)waitUntilExit; |
| 68 | + // poll the runLoop in defaultMode until task completes |
| 69 | + |
| 70 | +@end |
| 71 | + |
| 72 | +FOUNDATION_EXPORT NSString * const NSTaskDidTerminateNotification; |
| 73 | + |
0 commit comments