Monday, 25 March 2019

Objective-C, NSTask Buffer Limitation

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
                         encoding:NSUTF8StringEncoding];

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

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



from Objective-C, NSTask Buffer Limitation

No comments:

Post a Comment