Re: Wrapping an Interactive Unix Executable (update)
Re: Wrapping an Interactive Unix Executable (update)
- Subject: Re: Wrapping an Interactive Unix Executable (update)
- From: Harilaos Skiadas <email@hidden>
- Date: Fri, 17 Dec 2004 01:09:53 -0800 (PST)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
>Thanks for all of the replies, but I'm still having
some problems.
>
>I've looked over the NSTask documentation, and I
think I can use the
>standard input and output stuff, but I haven't yet
figured out how. At
>this point I'm able to launch the NSTask and get the
initial output,
>which is good. But as soon as I try to send it new
input (by writing
>to the NSFileHandle associated with the
standardInput) it crashes. I
>think I can get it to work if I use the notification
center, but I'd
>have to do everything in my controller class, but I'd
rather keep
>things separated as they are now in a controller
class and translator
>class. Thanks again for the help.
Can you show us some of your code? I haven't had many
problems with this. Basically, I get the task running
with (arguments is an NSArray containing the
information for the tool, task is an NSTask):
[task setStandardInput: [NSPipe pipe]];
[task setStandardOutput: [NSPipe pipe]];
[task setStandardError: [task standardOutput]];
[task setLaunchPath: [arguments objectAtIndex:0]];
[task setArguments: [arguments subarrayWithRange:
NSMakeRange (1, ([arguments count] - 1))]];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(getData:)
name: NSFileHandleReadCompletionNotification
object: [[task standardOutput]
fileHandleForReading]];
[[[task standardOutput] fileHandleForReading]
readInBackgroundAndNotify]; //You need to call this
from getData: too
// In order to have it read more.
[task launch];
Then when I want to send more data, I call:
NSData *dataToSend=[aString dataUsingEncoding
NSUTF8StringEncoding];
[[[task standardInput] fileHandleForWriting]
writeData:dataToSend];
Then to terminate:
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:NSFileHandleReadCompletionNotification object:
[[task standardOutput] fileHandleForReading]];
[task terminate];
[task release];
Can you tell us what the unix executable you are
trying to use is? Maybe you mentioned it already, but
I missed the beginning of this thread. Some programs
are very picky about being run from something which is
not a terminal. Some of them need you to set a switch
so that they know they are not talking to a terminal.
Btw, if you search the archives you can find more info
on this, eg:
http://www.cocoabuilder.com/archive/message/2004/8/26/115642
I hope this helps,
Haris
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden