A: 

I suspect you may not be able to do this. The percentage output will probably go to the terminal via curses (to permit in-place dynamic updating), and so there'll be a limited output via stdout.

It may be worth redirecting the output to a file and see what gets written there. i.e.

lame > /tmp/lame.log
Brian Agnew
Thanks for the suggestion. I checked the output file and it is holding all the individual percentage updates on separate lines. So reading each one should be possible.
kubi
It's also possible that lame outputs your figures and then outputs ^H (or backspaces). Thus grep may not get a carriage-return to allow it to identify an EOL. Lame may also change its output depending on where stdout is being sent to
Brian Agnew
A: 

lame is probably not outputting this information in the same way when not connected to a terminal. Try running your lame command with at the end "> output.txt" and look at what it's printing when attached to another process.

The other very likely possibility is that "17%" is never actually printing out. What probably is printing is:

%, move left, 1, move left, 2, move left 3, ... move left, move left, 1, 7, move left 8, etc.

Rob Napier
A: 

I ended up using NSScanner to parse the output. Each line from the NSTask was sent to this method:

- (NSNumber *)parseOutputString:(NSString *)output {
  NSScanner *scanner = [NSScanner scannerWithString:output];
  NSString *endString = @"% complete";
  NSInteger percentComplete;
  BOOL didFindNumber = NO;

  while (![scanner scanString:endString intoString:nil]) {
        [scanner scanUpToCharactersFromSet:[NSCharacterSet decimalDigitCharacterSet] intoString:nil];
        didFindNumber = [scanner scanInteger:&percentComplete];

        if ([scanner isAtEnd]) {
              didFindNumber = NO;
              break;
        }
  }

  if (didFindNumber) {
        return [NSNumber numberWithInteger:percentComplete];
  } else {
        return [NSNumber numberWithInt:0];
  }
}
kubi