NSTask and uudecode
I have to decode a uuencoded NSString in memory so I use NSTask to launch the unix command uudecode. If I set the output to a file, it works. But if I setStandardOutput to a NSFileHandle I cannot later get any availableData. Can you please tell me why?
// -p should set the standard output. Even without this args, it fails. NSArray *args = [NSArray arrayWithObjects:@"-p", nil]; [task setLaunchPath:@"/usr/bin/uudecode"]; [task setArguments:args];
I set the Standard input to the handle managing the string
NSPipe *writePipe = [NSPipe pipe]; NSFileHandle *writeHandle = [writePipe fileHandleForWriting]; [task setStandardInput:writePipe]; [writeHandle writeData:[uuencodedString dataUsingEncoding:NSMacOSRomanStringEncoding]]; [writeHandle closeFile];
I set a StandardOutput to a readHandle
NSPipe *readPipe = [NSPipe pipe]; NSFileHandle *readHandle = [readPipe fileHandleForReading]; [task setStandardOutput:readHandle];
Then I launch and wait [task launch]; [task waitUntilExit];
I cannot later get any data with
NSData *dataOut = [readHandle availableData];
The application doesn’t go further. It remains blocked here. What do I miss? Please note that if I set the standard output to a file
NSArray *args = [NSArray arrayWithObjects:@"-o", outFilePath, nil];
it properly works.
On Jan 27, 2010, at 9:37 AM, gMail.com wrote: