communication with an NSTask
communication with an NSTask
- Subject: communication with an NSTask
- From: Daniel Aarno <email@hidden>
- Date: Fri, 16 May 2003 23:38:11 +0200
I have one application that which to launch another and read some
status. If this status is OK the first application should exit and the
other persist, however if there is something wrong with the output from
#2 the first app should display some error.
The problem is that when all goes well and app 1 exits, app 2 dies! I
guess this is because the stdout, stderr file descriptors of app 2 is
not closed correctly and further writes to them will results in invalid
writes. Is this true?
What is the correct way to solve this problem?
/Bishop
What I do is something like this:
/////////////// BEGIN SNIPPET //////////////////////////
//Function 1 - "main"
caPipe = [[NSPipe alloc] init];
[crackAttack setStandardOutput : caPipe];
caPipe = [[NSPipe alloc] init];
[crackAttack setStandardError : caPipe];
[crackAttack setArguments : args];
[crackAttack setLaunchPath : path];
[crackAttack setCurrentDirectoryPath : [[NSBundle mainBundle]
resourcePath]];
[crackAttack launch];
ReadFromStdOutStdErrAndDoStuff();
exit(0);
//Function 2 - " ReadFromStdOutStdErrAndDoStuff()"
caPipe = [crackAttack standardOutput];
[caPipe autorelease];
caOut = [caPipe fileHandleForReading];
caPipe = [crackAttack standardError];
[caPipe autorelease];
caErr = [caPipe fileHandleForReading];
DoStuff(caErr, caOut);
return;
/////////////// END SNIPPET ////////////////////////////
_______________________________________________
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.