wood burning stoves 2.0
The moose likes Java in General and the fly likes Calling Perl from Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Calling Perl from Java" Watch "Calling Perl from Java" New topic

Calling Perl from Java

y Isola

Joined: Aug 19, 2010
Posts: 4

I'm trying to run perl script using java by :

Here is my perl script :

My problem is that, apparently the system() calls are not done.

Is it possible to call the command system through perl using java ?

Any idea why ?


Paul Clapham

Joined: Oct 14, 2005
Posts: 19687

"Apparently"? You aren't sure?

The command shell neither knows nor cares that a Java program is executing it. So your question is the wrong one. I would start by making sure that you didn't make a bad assumption about the current working directory of that script; if you did, you would have looked in the wrong place for the supposed output files and wouldn't have found them.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

You need to read the 4 sections of http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html and implement the recommendations. You are falling for at least two of the traps.

In particular you must handle 'stderr' (your failure to do so meant you did not see the error message saying the perl script could not be found) and you must either specify the current working directory so the the perl scipt is found or you must specify the full path to the perl script.

i.e. Either


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20046

Or use a ProcessBuilder and call redirectErrorStream(true) on it. This will merge stdout and stderr, leaving only one stream to be read.

How To Ask Questions How To Answer Questions
I agree. Here's the link: http://aspose.com/file-tools
subject: Calling Perl from Java
It's not a secret anymore!