ASObjC Explored NSTask + NSPipe: error.

Hello,

I’m working on NSTask and Pipe, in particularly on the script at page 215 of Shane Stanley’s book.
I copied the whole script and inserted the call of the method inside a button:


on buttonClicked:sender
doShellScriptInBackgroud:theScript callback:"dataIsReady:"
end buttonClicked:

By pressing the button I get this error:

2014-09-29 16:35:48.696 Test[604:303] *** -[AppDelegate doShellScriptInBackgroud:callback:]: unrecognized selector sent to object <AppDelegate @0x60000003cc80: OSAID(9) ComponentInstance(0x810000)> 2014-09-29 16:35:48.700 Test[604:303] *** -[AppDelegate buttonClicked:]: *** -[AppDelegate doShellScriptInBackgroud:callback:]: unrecognized selector sent to object <AppDelegate @0x60000003cc80: OSAID(9) ComponentInstance(0x810000)> (error -10000)
Any help?

Thanks in advance!

Hi,

the error message says there’s a typo in the handler definition - doShellScriptInBackgroud with missing n at the end

Thank you! That was the error…

But I have a further question: how can I get live output but the NSNotificationCenter, i.e. how can I get the exact single line of the output of the shell script?

you have to parse the text with a string parser like NSScanner or maybe NSRegularExpression

But the selector of the observer when is called and how many times?

the task is asynchronous, write the output continuously into a buffer until the data pointer is empty, meanwhile parse the text in the buffer

And how can I do that? Because as it is now, it just gives an output when the task is finished, so I get lines of output in once, and it’s not what I need…

you need the NSFileHandleReadCompletionNotification notification.

There are some examples on this forum

Thank you, it worked!