开发者

Call Perl Library from Objective-C cocoa

开发者 https://www.devze.com 2023-02-08 09:42 出处:网络
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.

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] );
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号