wood burning stoves 2.0*
The moose likes Java in General and the fly likes perl.exe thru 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 "perl.exe thru java" Watch "perl.exe thru java" New topic

perl.exe thru java

ramprasad nagaraja

Joined: Sep 12, 2001
Posts: 1
I want to invoke perl exe from java.It does not seem to work with Runtime.exe like the other exes.Any clue?
The piece of code is
Process stopRPSproc = Runtime.getRuntime().exec("perl.exe");
the call just comes out
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
First, try using the complete (absolute) path to the perl.exe file - e.g. C:\programs\perl\perl.exe or whatever. It's possible to use a relative path also, but you need to know what directory java is executing from, and where perl.exe is relative to that; if you have any problems, it's easiest to use the absolute path.
If this does not work, try using the Process method getErrorStream(), read from the InputStream it gives you, and print the results to your screen or a file somewhere. Chances are good there's an error message here which will give you further clues. Good luck.

"I'm not back." - Bill Harding, Twister
shanmuga perumal

Joined: Sep 14, 2003
Posts: 2
Can I get the output from perl file, which can be invoked by .java file
For Example
Process p = Runtime.getRuntime().exec("perl filename.pl argument.txt")
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12761
Look at the java.lang.Process API - in particular the
methods. These methods let you read and write the standard in, out and err streams that Perl uses
If your Perl program writes output to the screen you must read it or the Perl program may hang. Separate threads for reading the out and err are a good idea.
shanmuga perumal

Joined: Sep 14, 2003
Posts: 2
Hi Brogden,
Shall I use perl language in jsp tags instead of java. Pls explain with example
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12761
If you start Perl, it is going to expect input of a Perl program from somewhere - usually from a file - plus possibly command line parameters.
The only control you would have from JSP would be in setting up the command line to Perl.
raimondas zemaitis
Ranch Hand

Joined: Feb 23, 2001
Posts: 104
On a windows 2000 you should do in the following way to invoke external process (doesn't matter perl or other, BTW, I had to invoke Perl scripts in our current script and this works great):
String[] command = new String[3];
command[0] = "cmd.exe";
command[1] = "/C";
command[2] = "perl.exe";
Process proc = Runtime.getRuntime().exec(command);
It is sorta covered in the JavaRanch Style Guide.
subject: perl.exe thru java
Similar Threads
calling perl from Java
Running perl through java
How do i invoke a perl file using exec() in java
File Search
Running Perl on WLS 8.1 Sp2