Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Invoke perl script from a Java program

by fmerges (Chaplain)
on Aug 11, 2009 at 13:11 UTC ( #787608=note: print w/replies, xml ) Need Help??


in reply to Invoke perl script from a Java program

Hi,

Check this example, to get an idea: http://javaevangelist.blogspot.com/2008/08/making-system-call-in-java.html

Regards,

fmerges at irc.freenode.net
  • Comment on Re: Invoke perl script from a Java program

Replies are listed 'Best First'.
Re^2: Invoke perl script from a Java program
by Anonymous Monk on Aug 11, 2009 at 15:05 UTC
    The clunky way I've used in the past was basically to call Runtime.exec(String[]) like this:
    String[] command = new String[]{"perl", scriptName, arg1}; try { Runtime r = Runtime.getRuntime(); Process p = r.exec(command); // Read the results InputStream in = p.getInputStream(); // ... in.close(); } catch(Exception e) { e.printStackTrace(); }

    The downside is that (at least on a Unix-like system) the Runtime#exec() call has to fork a copy of the Java VM, so you need plenty of RAM to get away with this.

    I've sure there must be some cleverer way using JNI, but I've never got my head around it.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://787608]
help
Chatterbox?
Corion orders some gifts online :)
[ambrus]: We're spending Christmas and the week after at my brother's place. First time ever, because the last four years they could came home instead.
[ambrus]: robby_dobby: wait what? Glasgow? isn't that one of the most boring towns ever?
[marto]: ambrus: no :)
[robby_dobby]: ambrus: Dunno. marto is from Glasgow. I'm in London and I say London is quite colourful, but boring :-)

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2017-12-15 10:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (431 votes). Check out past polls.

    Notices?