Re: NSTask interaction
Re: NSTask interaction
- Subject: Re: NSTask interaction
- From: Ondra Cada <email@hidden>
- Date: Mon, 19 Nov 2001 01:18:01 +0100
Michael,
>
>>>>> Michael Mulligan (MM) wrote at Sun, 18 Nov 2001 13:10:18 -0500:
MM> NSTask, you can only pass it arguments once, correct? My problem is that
MM> I need to further interact with the task--I don't want it to simply end.
MM> I want to keep passing it data and getting the output into an NSString
MM> for parsing. I am under the impression that an NSPipe comes into play,
Quite right.
MM> but I am really confused about all of this. Is this possible and if so,
MM> how would I do it?
I kinda recall there was an example somewhere... Well, generally, it might
look more or less like this (just for stdout here):
=== cut here ===
NSTask *task=[[NSTask alloc] init];
NSPipe *opipe=[NSPipe pipe];
NSFileHandle *output=[opipe fileHandleForReading];
[task setLaunchPath:...];
[task setArguments:...];
[task setStandardOutput:opipe];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(gotData:) name:NSFileHandleDataAvailableNotification
object:output]; // async read
[output waitForDataInBackgroundAndNotify];
...
[task launch];
[task waitUntilExit];
=== cut here ===
See the apropriate classes (NSPipe, NSFileHandle,...) for details.
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
2K Development: email@hidden
http://www.2kdevelopment.cz
private email@hidden
http://www.ocs.cz/oc