Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

perl.exe thru java

 
ramprasad nagaraja
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
shanmuga perumal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic