NSTask.h 1.8 KB

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