• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java calling perl

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Has anyone ever come up with a way to call a Perl program from Java? If so, how are input and output handled?
Thanks,
Tarun
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe the standard way is with the Runtime exec() method. I don't know a platform-neutral way to do this, but usually the only thing that changes from system to system is the path to the perl execuatble - so make this user-configurable (like with a properties file) and this isn't too big a deal. For communications you have a number of options - exec() returns a Process, which has getInputStream(), getOutputStream(), and the not-to-be-forgotten getErrorStream() method, which allow communication with the process (your perl script with perceive these as its standard input, standard output, and standard error, respectively. But these are oftern a pain to work with - it's often easier to communicate through files. Put the data you want processed in one file, and have the perl script output its results in another file. Assuming that sort of arrangement makes sense for what you're doing. I assume perl can also communicate through sockets, so that's also an option if you prefer.
Lastly, if you're not too committed to perl already, you might want to look at the Python programming language, which is perhaps perl's biggest rival among interpreted languages. It's much more readable, and there's a Java implementation known as Jython, which is very easy to interface with in a platform-neutral manner. Check out www.python.org and www.jython.org. Enjoy...
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about a slightly less complex & perhaps more universally needed solution...
A java servlet passing CGI variables to a perl script for the perl script to consume & vice versa. How would one do that particularly when the perl script is likely running under a different port ( eg, 80) & the servlet ( eg Tomcat ) is running under 8080???
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, it depends what you are using perl for? If its just for the powerful regular expressions, then Java has implemented simlar regular expression support in Java 1.4:
http://java.sun.com/j2se/1.4/docs/api/java/util/regex/package-summary.html
If you are stuck with an earlier version of Java, then Apache have a open source version you could try:
http://jakarta.apache.org/regexp/index.html
Have fun
 
You ought to ventilate your mind and let the cobwebs out of it. Use this cup to catch the tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic