This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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
Author

perl.exe thru java

ramprasad nagaraja
Greenhorn

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
Wanderer
Sheriff

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
Greenhorn

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
Rancher

Joined: Mar 22, 2000
Posts: 12791
    
    5
Look at the java.lang.Process API - in particular the
getErrorStream
getInputStream
getOutputStream
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.
Bill
shanmuga perumal
Greenhorn

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
Rancher

Joined: Mar 22, 2000
Posts: 12791
    
    5
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.
Bill
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);
 
GeeCON Prague 2014
 
subject: perl.exe thru java