Trying to capture standard error from an NSTask
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