MYUtilities / MYTask.h

//  MYTask.h
//  Murky
//  Copyright 2008 Jens Alfke. All rights reserved.

#import <Cocoa/Cocoa.h>

extern NSString* const MYTaskErrorDomain;
extern NSString* const MYTaskExitCodeKey;
extern NSString* const MYTaskObjectKey;
enum {
    kMYTaskError = 2

@interface MYTask : NSObject 
    NSString *_command;
    NSMutableArray *_arguments;
    NSString *_currentDirectoryPath;
    NSTask *_task;
    int _resultCode;
    NSError *_error;
    BOOL _ignoreOutput;
    NSFileHandle *_outHandle, *_errHandle;
    NSMutableData *_outputData, *_errorData;
    NSString *_output;
    NSMutableArray *_modes;
    BOOL _isRunning, _taskRunning;
    CFAbsoluteTime _startTime;

- (id) initWithCommand: (NSString*)subcommand, ... NS_REQUIRES_NIL_TERMINATION;

/* designated initializer (subclasses can override) */
- (id) initWithCommand: (NSString*)subcommand
             arguments: (NSArray*)arguments;

- (id) initWithError: (NSError*)error;

- (void) addArgument: (id)argument;
- (void) addArguments: (id)arg1, ... NS_REQUIRES_NIL_TERMINATION;
- (void) addArgumentsFromArray: (NSArray*)arguments;
- (void) prependArguments: (id)arg1, ... NS_REQUIRES_NIL_TERMINATION;

- (void) ignoreOutput;

@property (copy) NSString* currentDirectoryPath;

/** Prettified description of command string. Doesn't do full shell-style quoting, though. */
- (NSString*) commandLine;

- (BOOL) run;
- (BOOL) run: (NSError**)outError;

- (BOOL) start;
- (void) stop;
- (BOOL) waitTillFinished;

@property (readonly,nonatomic) BOOL isRunning;
@property (readonly,retain,nonatomic) NSError* error;
@property (readonly,nonatomic) NSString *output, *outputAndError;
@property (readonly,nonatomic) NSData *outputData;

// protected:

/** Subclasses can override this to add arguments or customize the task */
- (NSTask*) createTask;

/** Sets the error based on the message and parameters. Always returns NO. */
- (BOOL) makeError: (NSString*)fmt, ...;

/** Called when the task finishes, just before the isRunning property changes back to NO.
    You can override this to do your own post-processing. */
- (void) finished;

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.