On 18 May 2010, at 21:13, Jens Alfke wrote:

> 
> On May 18, 2010, at 12:33 PM, appledev wrote:
> 
>> I dont want to use a call to a bash script, because of sneaking in bad 
>> commands.
> 
> As others said, it’s not a problem here because the command line is entirely 
> hardcoded.
> 
> If you wanted to avoid using a shell, you’d have to start three separate 
> NSTasks for the three commands (df, grep, awk) and hook the output pipe of 
> one to the input of the next. I’m not sure how to do that.

Something like the following should work, right?

  NSTask *task1 = [[[NSTask alloc] init] autorelease];
  NSTask *task2 = [[[NSTask alloc] init] autorelease];
  NSTask *task3 = [[[NSTask alloc] init] autorelease];
  NSPipe *t1t2pipe = [NSPipe pipe];
  NSPipe *t2t3pipe = [NSPipe pipe];
  NSPipe *outputPipe = [NSPipe pipe];

  [task1 setLaunchPath:@"/bin/df"];
  [task1 setArguments:[NSArray arrayWithObjects:@"-k", nil]];
  [task1 setStandardOutput:t1t2pipe];
  
  [task2 setLaunchPath:@"/usr/bin/grep"];
  [task2 setArguments:[NSArray arrayWithObjects:@"/dev/", nil]];
  [task2 setStandardInput:t1t2pipe];
  [task2 setStandardOutput:t2t3pipe];

  [task3 setLaunchPath:@"/usr/bin/awk"];
  [task3 setArguments:[NSArray arrayWithObjects:@"{print $1 \"\t\" $4 \"\t\" $5 
\"\t\" $6;}", nil]];
  [task3 setStandardInput:t2t3pipe];
  [task3 setStandardOutput:outputPipe];

  [task1 launch];
  [task2 launch];
  [task3 launch];

Kind regards,

Alastair.

--
http://alastairs-place.net



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to