Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,
I dont know if this is the correct forum for this query , but if possible please help me on this

I want to invoke my perl script from a java program.Can you please give pointers as to how this can be implemeneted.

Replies are listed 'Best First'.
Re: Invoke perl script from a Java program
by fmerges (Chaplain) on Aug 11, 2009 at 13:11 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.

Re: Invoke perl script from a Java program
by chorny (Scribe) on Aug 11, 2009 at 13:32 UTC