I’m using NSTask to ‘talk to’ a command line executable that is embedded in my app. I use NSPipe as its stdIn and stdOut channels.
When I run the code under Xcode, it works fine. When I build the app into a standalone executable, it fails with a “broken pipe 13” error message and immediate termination.
Aug 11 09:01:23 The-New-iMac com.apple.xpc.launchd (net.apptree.checkmate.Checkmate.61324): Service exited due to signal: Broken pipe: 13 sent by Checkmate
The code seems pretty straightforward, so I can’t see anything tricky. Any ideas what could be causing this?
NSBundle* mainBundle = [NSBundle mainBundle];
NSString* executablePath = [mainBundle pathForAuxiliaryExecutable:@"crafty"];
NSString* resourcePath = [mainBundle resourcePath];
mCrafty = [[NSTask alloc] init];
mCrafty.launchPath = executablePath;
mCrafty.arguments = @[@"ponder off",@"noise 1000000",@"sn 10",@"sd 10"];
NSMutableDictionary* environment = [NSMutableDictionary dictionary];
[environment setObject:resourcePath forKey:@"CRAFTY_BOOK_PATH"];
mCrafty.environment = environment;
- (void) initStdIn
NSPipe* inputToCrafty = [NSPipe pipe];
mCrafty.standardInput = inputToCrafty;
- (void) initStdOut
NSPipe* craftyOutput = [NSPipe pipe];
craftyOutput.fileHandleForReading.readabilityHandler = ^(NSFileHandle* fileHandle)
//[all the stuff that parses the output deleted for clarity]
mCrafty.standardOutput = craftyOutput;
Note: For the standalone executable, I don’t see any of the logged (NSLog) messages. I’m not sure why. One difficulty is that the revised Console app makes it a lot harder to figure out what the hell I’m looking at. system.log contains the SIGPIPE error, but none of the log messages. Where did they go?