• 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
Trying to capture standard error from an NSTask
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Trying to capture standard error from an NSTask


  • Subject: Trying to capture standard error from an NSTask
  • From: <email@hidden>
  • Date: Wed, 2 Mar 2005 8:03:59 +0000

I am currently trying to capture standard error from an NSTask, and display an alert box with the error string.  This is how I'm currently implementing things, and I'll explain what's happening after:

NSTask* task = [[NSTask alloc] init];
NSPipe* errorPipe = [[NSPipe alloc] init];
NSFileHandle* errorReader = [errorPipe fileHandleForReading];

[task setLaunchPath:someprocess];
[task setArguments:somearguments];
[task setStandardError:errorPipe];

[task launch];
[task waitUntilExit];

NSString* errorString = [[NSString alloc] initWithData:[errorReader readDataToEndOfFile] encoding:nil];

if ([error length] != 0)
{
   // do stuff
}
else // resume normal operation.

The thing is, when I run this in the debugger, it hits the line if ([error length] != 0) and goes into that block.  But if I change it to say [error length] == 0, it still enters the block!  So my string doesn't have a length but does at the same time?

What I'm doing in the block is setting a BOOL flag to yes, and wrting the error string to an NSTextView that I'll show later when I test the value of the error flag.

But for some reason my application thinks that the string has a length but has no length, and I'm kinda confused.  Hope y'all can help me out.

James

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Trying to capture standard error from an NSTask
      • From: Scott Ribe <email@hidden>
    • Re: Trying to capture standard error from an NSTask
      • From: j o a r <email@hidden>
  • Prev by Date: connecting custom formatter to tableView column
  • Next by Date: Re: Trying to capture standard error from an NSTask
  • Previous by thread: Re: connecting custom formatter to tableView column
  • Next by thread: Re: Trying to capture standard error from an NSTask
  • Index(es):
    • Date
    • Thread