1. Peter Hosey
  2. PRHTask


Peter Hosey  committed 66d6152

Implemented the environment property.

  • Participants
  • Parent commits dc6d1af
  • Branches default

Comments (0)

Files changed (2)

File PRHTask.h

View file
  *It also uses formal properties wherever appropriate and (currently) uses GCD internally.
  *Currently, this does not provide any way to hook standard input up to anything. You can either let it be inherited (default, as in NSTask) or nullify it (connect it to /dev/null).
- *Also, this does not yet have a formal version of NSTask's environment property. Until then, setting the process's environment is unsupported.
 @class PRHTask;
 @property(copy) id standardOutput;
 @property(copy) id standardError;
+@property(copy) NSDictionary *environment;
 #pragma mark -
 @property(readonly) pid_t processIdentifier;

File PRHTask.m

View file
 @synthesize standardOutput;
 @synthesize standardError;
+@synthesize environment;
 @synthesize trimWhitespaceFromAccumulatedOutputs;
 @synthesize accumulatedStandardOutputData;
 	[self connectPipe:self.standardOutput toFileDescriptor:STDOUT_FILENO];
 	[self connectPipe:self.standardError toFileDescriptor:STDERR_FILENO];
+	for (NSString *key in self.environment) {
+		NSString *value = [self.environment objectForKey:key];
+		setenv([key UTF8String], [value UTF8String], /*overwrite*/ 1);
+	}
 	char **argv = malloc(sizeof(char *) * ([args count] + 1));
 	char **argvp = argv;