#StackBounty: #ios #objective-c #xcode #macos #nstask Objective-C, NSTask Buffer Limitation

Bounty: 50

I’m using NSTask to run an external utility which returns a long string of data. The problem is that when the returned string exceeds 4096 bytes it becomes null. How do I return more than 4096 bytes?

NSTask *myTask = [[NSTask alloc] init];

[myTask setLaunchPath:myExternalCommand];
[myTask setArguments:[NSArray arrayWithObjects: arg1, arg2, nil]];

NSPipe *pipe = [NSPipe pipe];
[myTask setStandardOutput:pipe];

NSFileHandle *taskHandle;
taskHandle = [pipe fileHandleForReading];

[myTask launch];
[myTask waitUntilExit];

NSData *taskData;
taskData = [taskHandle readDataToEndOfFile];

NSString *outputString = [[NSString alloc] initWithData:taskData

NSLog(@"Output: n%@", outputString);
// (null) when stdout exceeds 4096

*please note, I’m looking for an Obj-C solution, thanks.

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.