I have a C function that prints to stdout using fprintf
, and I'm attempting to display the contents of stdout in a UIAlertView
. My code is as follows:
NSFileHandle *stdoutFileHandle = [NSFileHandle fileHandleWithStandardOutput];
NSData *stdoutData = [stdoutFileHandle availableData];
NSString *stdoutString = [[NSString alloc] initWithData:stdoutData encoding:NSASCIIStringEncoding];
UIAlertView *stdoutAlert = [[UIAlertView alloc] initWithTitle:@"STDOUT OUTPUT" message:stdoutString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[stdoutAlert show];
I'm getting the following error when I run my code.
Terminating app due to uncaught exception 'NSFileHandleOperationException', reason: '[NSConcreteFileHandle availableData]: Bad file descriptor'
I get an equivalent error when I replace [stdoutFileHandle availableData]
with [stdoutFileHandle readDataToEndOfFile]
.