NSTask returns only standardError in release build

First of all, when debugging and running in Xcode, everything works as expected.

But when I try to "share" my application, i.e. to build the releases, my NSTask will not output any standard record until standard errors are issued. How is this possible?

My code

- (id)initWithWindow:(NSWindow *)window { self = [super initWithWindow:window]; if (self) { // Initialization code here. } [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(readPipe:) name:NSFileHandleReadCompletionNotification object:nil]; return self; } -(void) watchFile:(NSNotification *)notification { NSString *path = [[notification userInfo] valueForKey:@"path"]; task = [[NSTask alloc] init]; [task setLaunchPath:@"/usr/bin/compass"]; [task setCurrentDirectoryPath:path]; NSArray *arguments; arguments = [NSArray arrayWithObjects: @"watch",@"--boring", nil]; [task setArguments: arguments]; NSPipe *outPipe, *errPipe; outPipe = [NSPipe pipe]; errPipe = [NSPipe pipe]; [task setStandardOutput: outPipe]; [task setStandardError: errPipe]; [task setStandardInput: [NSPipe pipe]]; standardHandle = [outPipe fileHandleForReading]; [standardHandle readInBackgroundAndNotify]; errorHandle = [errPipe fileHandleForReading]; [errorHandle readInBackgroundAndNotify]; [self setSplitterPosition:0.0f]; [task launch]; } -(void)readPipe:(NSNotification *)notification { NSLog(@"reading pipe"); NSData *data; NSString *text; if(!([notification object] == standardHandle) && !([notification object] == errorHandle)) { return; } data = [[notification userInfo] objectForKey:NSFileHandleNotificationDataItem]; text = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; if ([data length] == 0) { //error [self setSplitterPosition:150.0f]; return; } [terminalViewController updateTerminal:text]; if(![text isEqualToString:@"\n"]) [self growlAlert:text title:@"Compapp"]; [text release]; if(task) [[notification object] readInBackgroundAndNotify]; } 
+1
source share
3 answers

/usr/bin/compass not binary installed in a standard OSX installation (I don't have a binary name named compass in my /usr/bin on my Mac)

So, it is logical that when your application runs on another Mac that does not have /usr/bin/compass installed and you try to run this task, it cannot find it and output some error to stderr.

0
source

If you mean after the release that you are trying to debug, you need to create a file called Entitlements.plist and you can set it up for debugging before you create and archive it.

0
source

if there is still an open problem for you, then check the answer that I posted at this link: How to use a specific NSProgressIndicator to check NSTask progress? - Cocoa

it provides a good template for creating asynchronous NSTask and for reading from standard output or standard error.

0
source

All Articles