Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling Perl from Java

 
y Isola
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21309
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 781
Java Netbeans IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Rob Spoor
Sheriff
Pie
Posts: 20606
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or use a ProcessBuilder and call redirectErrorStream(true) on it. This will merge stdout and stderr, leaving only one stream to be read.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic