Setting standard input with NSPipe
Setting standard input with NSPipe
- Subject: Setting standard input with NSPipe
- From: Ivan Myrvold <email@hidden>
- Date: Mon, 19 Jul 2004 18:32:37 +0200
I am having problems wrapping a Unix CLI application called asterisk in
Cocoa. As long as I don't set the standard input, the NSTextView that
shows the standard output of the Unix application works fine.
Asterisk is an interactive application, that you connects to (if it's
running) with "/usr/sbin/asterisk -r". You should then get a "*CLI>"
prompt, and can then give certain commands, e.g. "help".
In my button action method, that shall connect to asterisk, I have this:
[defaultCenter addObserver:self selector:@selector(taskCompleted:)
name:NSTaskDidTerminateNotification object:asterisk];
[asterisk setLaunchPath:@"/usr/sbin/asterisk"];
[asterisk setArguments:[NSArray arrayWithObjects:@"-r",nil]];
// set up the environment
[environment setObject:@"YES" forKey:@"NSUnbufferedIO"];
// set up pipe for stdout
outputPipe = [NSPipe pipe];
taskOutput = [outputPipe fileHandleForReading];
[defaultCenter addObserver:self
selector:@selector(taskDataAvailable:)
name:NSFileHandleReadCompletionNotification object:taskOutput];
[asterisk setStandardOutput:outputPipe];
This works fine, the *CLI> prompt is showing up in my NSTextView, and I
am happy. But my Cocoa application also is supposed to do more, as give
commands to asterisk while it is connected. Therefore I add an
inputPipe in the same button action, so that I can be able to do that:
// set up pipe for stdin
inputPipe = [NSPipe pipe];
taskInput = [inputPipe fileHandleForWriting];
[asterisk setStandardInput:inputPipe];
And now the strange thing happens, the NSTextView is getting filled up
with *CLI> *CLI> *CLI> *CLI> *CLI>......, and it never stops. I have to
force quit the cocoa application to get out of it.
Can anyone explain to me what happens? I have not sent any commands
through the inputPipe, yet this happens.
Ivan
_______________________________________________
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.