Call Perl library from Objective-C cocoa

I have a Perl library that I use to read some information from a file (closed format). This library reads the file and returns an array of objects with the result.

Now I need to integrate this library (I can’t implement it in cocoa right now) in a cocoa application. Basically call it and try to show the results in a list.

Is there some kind of bridge for calling Perl libraries from ObjectiveC and getting results?

I read something about using NSTask to directly call a perl script, and analyze the result, but I am wondering if this can be done directly.

Best wishes.

+4
source share
2 answers

You are absolutely right: NSTask is on a Cocoa (not Cocoa -Touch) class suitable for you. You can start any subprocess, given that this subprocess inherits the environment from your main task (but, of course, you can apply various settings, for example, the start directory). The advantage with respect to "system ()" is that the NSTask "start" method is not blocked, so you can use it for long asynchronous tasks (and receive completion notifications).

For a specific perl case, run the perl script as on the command line: "/ usr / bin / perl ..."

Finally, you can try with PerlObjCBridge (link: PerlObjCBridge.pm man page ) for a kind of interprocess communication between Objective-C and perl objects.

+1
source

If you need a bridge, check out PerlObjCBridge . If you just want to call a script, I believe you can just use system (). Something like that:

system( [scriptCallNSString UTF8String] ); 
0
source

Source: https://habr.com/ru/post/1338483/


All Articles