Call Perl Library from Objective-C cocoa
I have a Perl library i use to read some information from a file (closed format). This library reads a file and returns an array of objects with the result.
Now i have to integrate that library (cannot implement it in cocoa right now) in a cocoa app. Basically call it and try to show the results in a list.
Is there开发者_JAVA百科 some kind of bridge to call Perl libraries from ObjectiveC and get the results?
I've read something about using NSTask to call a perl script directly, and parse the result, but i wonder if it could be possible to do that call directly.
best regards.
You are perfectly right: NSTask is on Cocoa (not Cocoa-Touch) the right class for you. You can launch any subprocess, considering that this subprocess will inherit the environment from you main task (but of course you can apply different settings, e.g. the run directory). The advantage with respect to "system()" is that NSTask "launch" method is non blocking so you can use it for long aysnchronous jobs (and be notified when it is over).
For the specific case of perl, just run the perl script as in command line: "/usr/bin/perl ..."
Finally you can make a try with PerlObjCBridge (link: PerlObjCBridge.pm man page) for a sort of interprocess communication between Objective-C objects and perl.
If you want a bridge, take a look at PerlObjCBridge. If you just want to call the script, I believe you can just use system(). Something like this:
system( [scriptCallNSString UTF8String] );
精彩评论