Results 1 to 13 of 13
Thread: Calling Perl from Java
- 01-26-2012, 07:02 AM #1
Member
- Join Date
- Jan 2012
- Posts
- 10
- Rep Power
- 0
Calling Perl from Java
Hi All,
I need some information, could you please help me out.
I have a perl file at the location : D:\Work\Perl\Practice\hello.pl
I want to call this perl file in a java program, so in my java file i write below code in try catch block
Runtime r= Runtime.getRuntime();
Process p1=r.exec("cmd /C perl D:\\Work\\Perl\\Practice\\hello.pl");
Although code does not through exception, but the perl file does not perform the required action.
As it is supposed to create a file which it does not. And when i execute the perl file from command prompt then action is performed perfectly.
Any input on this ?Thanks & Regards,
Shah
- 01-26-2012, 10:35 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Re: Calling Perl from Java
Perl or the *.pl file is not an executable, and try "cmd /c start hello.pl" and see.
- 01-26-2012, 11:28 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Calling Perl from Java
Oh look, more spam from sharejutt.
I've reported them earlier...
- 01-26-2012, 12:04 PM #4
Member
- Join Date
- Jan 2012
- Posts
- 10
- Rep Power
- 0
Re: Calling Perl from Java
Thanks Eranga!
I tried this
Process p1=r.exec("cmd /c start D:\\Work\\Perl\\Practice\\hello.pl");
it only opens the perl file in notepad. Doesn't execute.
Please advise.
Thanks & Regards,
Shah
- 01-26-2012, 12:15 PM #5
Member
- Join Date
- Jan 2012
- Posts
- 10
- Rep Power
- 0
Re: Calling Perl from Java
Thanks Eranga!
I tried this
Process p1=r.exec("cmd /c start D:\\Work\\Perl\\Practice\\hello.pl");
it only opens the perl file in notepad. Doesn't execute.
Please advise.
Thanks & Regards,
Shah
- 01-26-2012, 01:11 PM #6
Re: Calling Perl from Java
You need to tell the OS what to do when a .pl file is "openned". It looks like the OS wants to use notepad to open the file.
Or you need to provide the path to the perl executeable (like perl.exe) with the file it is to execute. You could put the bin folder holding the perl.exe file on the OS's PATH.
- 01-26-2012, 01:17 PM #7
Member
- Join Date
- Jan 2012
- Posts
- 10
- Rep Power
- 0
Re: Calling Perl from Java
Thanks Norm,
Can you please provide me some code example of this or it will be great if you can update below one which I am using
Runtime r= Runtime.getRuntime();
Process p1=r.exec("cmd /c start D:\\Work\\Perl\\Practice\\hello.pl");
Many Thanks & Regards,
Shah
- 01-26-2012, 01:38 PM #8
Re: Calling Perl from Java
Something like:
r.exec("<path to bin>\\perl.exe D:\\Work\\Perl\\Practice\\hello.pl");
- 01-27-2012, 05:30 AM #9
Member
- Join Date
- Jan 2012
- Posts
- 10
- Rep Power
- 0
Re: Calling Perl from Java
Thanks Norm,
I tried this, but it doesn't call the file.
- 01-27-2012, 06:32 AM #10
Member
- Join Date
- Jan 2012
- Posts
- 10
- Rep Power
- 0
Re: Calling Perl from Java
Hi Norm,
Sorry, the script is working after your suggessions -
Actually the perl file is supposed to create a file and i was checking it on a supposed to be location. But the file is generating under the application folder. Which is fine.
Really thankful to Norm & Eranga.
Best Regards,
Shah
- 01-30-2012, 08:00 AM #11
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Re: Calling Perl from Java
You are welcome.
- 01-30-2012, 08:01 AM #12
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Re: Calling Perl from Java
- 02-06-2012, 01:05 PM #13
Member
- Join Date
- Jan 2012
- Posts
- 10
- Rep Power
- 0
Similar Threads
-
calling a perl script in Java(using a OK Button)
By Yaya B in forum NetBeansReplies: 1Last Post: 01-07-2011, 07:20 AM -
Including Perl in java
By swati.jyoti in forum New To JavaReplies: 1Last Post: 05-13-2010, 04:31 PM -
Perl in Java!
By hakan123 in forum New To JavaReplies: 5Last Post: 12-11-2009, 07:05 PM -
run perl script from java
By maheshmhs in forum New To JavaReplies: 0Last Post: 12-19-2008, 12:40 PM -
Use Perl function with java
By lenny in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 06:25 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks