• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSTask and piped commands
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTask and piped commands


  • Subject: NSTask and piped commands
  • From: appledev <email@hidden>
  • Date: Tue, 18 May 2010 21:33:09 +0200

I have to run the following and similar commands using NSTask.

df -k | grep  /dev/ |awk '{print $1 "\t" $4 "\t" $5 "\t" $6;}'

I got so far.....

NSTask *task;
    task = [[NSTask alloc] init];
    [task setLaunchPath: @"/bin/sh"];

    NSArray *arguments;
    arguments = [NSArray arrayWithObjects: @"-c", @"/bin/df -k| /usr/bin/grep /dev/ | /usr/bin/awk '{print $1 $4 $5 $6;}'",nil];
	// arguments = [NSArray arrayWithObjects: @"-c", @"/bin/df -k", @"| /usr/bin/grep /dev/ | /usr/bin/awk '{print $1 '\t' $4 '\t' $5 '\t' $6;}'",nil];
    NSLog ( @"%@", arguments );
    [task setArguments: arguments];

    NSPipe *pipe;
    pipe = [NSPipe pipe];
    [task setStandardOutput: pipe];
    NSFileHandle *file;
    file = [pipe fileHandleForReading];

    [task launch];

    [task waitUntilExit];

    NSData *data;
    result = [file readDataToEndOfFile];
    NSString *string;
    string = [[NSString alloc] initWithData: result encoding: NSUTF8StringEncoding];

I dont want to use a call to a bash script, because of sneaking in bad commands.
But how should I handle this?
Does someone has any advice?

Thanks_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSTask and piped commands
      • From: Alastair Houghton <email@hidden>
    • Re: NSTask and piped commands
      • From: Jens Alfke <email@hidden>
    • Re: NSTask and piped commands
      • From: "Stephen J. Butler" <email@hidden>
    • Re: NSTask and piped commands
      • From: Rick Genter <email@hidden>
  • Prev by Date: Re: Detecting modifier key down when opening a menu?
  • Next by Date: Re: NSTask and piped commands
  • Previous by thread: [iPhone] How to add a text field like that scales with return key like in iPhone Messages
  • Next by thread: Re: NSTask and piped commands
  • Index(es):
    • Date
    • Thread