//
//  NSTask+Quickies.h
//  BEToolkit
//
//  Created by Philipp on 5/26/08.
//  Copyright 2015 Incredible Bee Ltd. All rights reserved.
//

#import <Cocoa/Cocoa.h>


/*
 * WARNING!!!
 *
 * The methods in this class are not thread-safe:
 * - for some reasons the NSPipe instance created in the methods are NOT released until a
 *   thread's autorelease pool is released
 * - this means that if you run the methods in a loop then at some point (around 256 calls)
 *   the system runs out of file descriptors and will no longer generate NSPipes
 * - this results in a warning along the lines of "can't insert nil value into NSDictionary"
 *
 * Make sure to call the methods in this class from the main thread to avoid this problem
 */


@interface NSTask (DTCQuickies)

// Run the given command until completion and return the termination status
+(int) run:(NSString *)aCommand withArguments:(NSArray *)anArgumentList;

// Run the given command until completion, return the termination status and store the output in aString
+(int) run:(NSString *)aCommand withArguments:(NSArray *)anArgumentList output:(NSString **)aString;

// Runs the given command and returns the output
+ (NSString *) runCommand:(NSString *)aCommand withArguments:(NSArray *)anArgumentList;

// Run a sequence of piped commands
+(int) runPipe:(NSString *)pipedCommands output:(NSString **)aString;

@end
