Re: Dumping input to NSTask
Re: Dumping input to NSTask
- Subject: Re: Dumping input to NSTask
- From: John Timmer <email@hidden>
- Date: Wed, 14 Jul 2004 22:15:46 -0400
>
If you are not creating your own input and output pipes or file
>
handles, then that could be the problem. If you have created an
>
NSPipe instance to be used as the input, the write end is close when
>
the task is launched, so you need to send the data before you launch
>
the task.
Ah, that was definitely something I did wrong - thanks. Even so, I wind up
with the task hanging. The following's the chunk of code that's causing me
trouble - it stops right at the waitUntilExit indefinitely. If there's
anything else I'm obviously doing wrong, I'd appreciate hearing about it.
Otherwise, I'll assume it's just some peculiarity with the executable I'm
running and send things through a few files in /tmp.
NSTask *tempTask = [[NSTask alloc] init];
[tempTask setLaunchPath: theExecutablePath];
[tempTask setArguments: [NSArray arrayWithObject: @"-format_output"]];
NSPipe *readPipe = [NSPipe pipe];
[tempTask setStandardOutput: readPipe];
NSFileHandle *readHandle = [readPipe fileHandleForReading];
NSPipe *writePipe = [NSPipe pipe];
[tempTask setStandardInput: writePipe];
NSFileHandle *writeHandle = [writePipe fileHandleForWriting];
NSData *queryBytes = [NSData dataWithBytes: [theQuery UTF8String]
length: [theQuery length]];
[writeHandle writeData: queryBytes];
[tempTask launch];
[tempTask waitUntilExit];
_______________________________________________
This mind intentionally left blank
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.