Skip to content
Browse files

PBEasyPipe: Add method that allows you to specify the environment stuff

  • Loading branch information...
1 parent 78eeab4 commit 57168e1ab061c1097b231eb705b05a77136fe95d @pieter pieter committed
Showing with 26 additions and 3 deletions.
  1. +7 −0 PBEasyPipe.h
  2. +19 −3 PBEasyPipe.m
View
7 PBEasyPipe.h
@@ -28,5 +28,12 @@
inDir:(NSString *) dir
inputString:(NSString *)input
retValue:(int *) ret;
++ (NSString*) outputForCommand:(NSString *) cmd
+ withArgs:(NSArray *) args
+ inDir:(NSString *) dir
+ byExtendingEnvironment:(NSDictionary *)dict
+ inputString:(NSString *)input
+ retValue:(int *) ret;
+
@end
View
22 PBEasyPipe.m
@@ -51,17 +51,33 @@ + (NSString*) outputForCommand:(NSString *) cmd
inDir:(NSString *) dir
retValue:(int *) ret
{
- return [self outputForCommand:cmd withArgs:args inDir:dir inputString:NULL retValue:ret];
+ return [self outputForCommand:cmd withArgs:args inDir:dir byExtendingEnvironment:nil inputString:nil retValue:ret];
}
-// TODO: Refactor this to use the function above
+ (NSString*) outputForCommand:(NSString *) cmd
withArgs:(NSArray *) args
inDir:(NSString *) dir
- inputString:(NSString *)input
+ inputString:(NSString *) input
retValue:(int *) ret
{
+ return [self outputForCommand:cmd withArgs:args inDir:dir byExtendingEnvironment:nil inputString:input retValue:ret];
+}
+
++ (NSString*) outputForCommand:(NSString *) cmd
+ withArgs:(NSArray *) args
+ inDir:(NSString *) dir
+ byExtendingEnvironment:(NSDictionary *)dict
+ inputString:(NSString *) input
+ retValue:(int *) ret
+{
NSTask *task = [self taskForCommand:cmd withArgs:args inDir:dir];
+
+ if (dict) {
+ NSMutableDictionary *env = [[[NSProcessInfo processInfo] environment] mutableCopy];
+ [env addEntriesFromDictionary:dict];
+ task.environment = env;
+ }
+
NSFileHandle* handle = [task.standardOutput fileHandleForReading];
if (input) {

0 comments on commit 57168e1

Please sign in to comment.
Something went wrong with that request. Please try again.