aspose file tools*
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "Calling Perl from Java" Watch "Calling Perl from Java" New topic
Author

Calling Perl from Java

y Isola
Greenhorn

Joined: Aug 19, 2010
Posts: 4
Hi,

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 ?

thanks,

Apocys
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

"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


or



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

Joined: Oct 27, 2005
Posts: 19696
    
  20

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling Perl from Java