Results 1 to 13 of 13
  1. #1
    Shabber102 is offline Member
    Join Date
    Jan 2012
    Posts
    10
    Rep Power
    0

    Default 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

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default Re: Calling Perl from Java

    Perl or the *.pl file is not an executable, and try "cmd /c start hello.pl" and see.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default Re: Calling Perl from Java

    Oh look, more spam from sharejutt.
    I've reported them earlier...

  4. #4
    Shabber102 is offline Member
    Join Date
    Jan 2012
    Posts
    10
    Rep Power
    0

    Default 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

  5. #5
    Shabber102 is offline Member
    Join Date
    Jan 2012
    Posts
    10
    Rep Power
    0

    Default 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

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,572
    Rep Power
    25

    Default 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.

  7. #7
    Shabber102 is offline Member
    Join Date
    Jan 2012
    Posts
    10
    Rep Power
    0

    Default 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

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,572
    Rep Power
    25

    Default Re: Calling Perl from Java

    Something like:

    r.exec("<path to bin>\\perl.exe D:\\Work\\Perl\\Practice\\hello.pl");

  9. #9
    Shabber102 is offline Member
    Join Date
    Jan 2012
    Posts
    10
    Rep Power
    0

    Default Re: Calling Perl from Java

    Thanks Norm,

    I tried this, but it doesn't call the file.

  10. #10
    Shabber102 is offline Member
    Join Date
    Jan 2012
    Posts
    10
    Rep Power
    0

    Default 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

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default Re: Calling Perl from Java

    Quote Originally Posted by Tolls View Post
    Oh look, more spam from sharejutt.
    I've reported them earlier...
    Seems no more.

  13. #13
    Shabber102 is offline Member
    Join Date
    Jan 2012
    Posts
    10
    Rep Power
    0

Similar Threads

  1. Replies: 1
    Last Post: 01-07-2011, 07:20 AM
  2. Including Perl in java
    By swati.jyoti in forum New To Java
    Replies: 1
    Last Post: 05-13-2010, 04:31 PM
  3. Perl in Java!
    By hakan123 in forum New To Java
    Replies: 5
    Last Post: 12-11-2009, 07:05 PM
  4. run perl script from java
    By maheshmhs in forum New To Java
    Replies: 0
    Last Post: 12-19-2008, 12:40 PM
  5. Use Perl function with java
    By lenny in forum Advanced Java
    Replies: 1
    Last Post: 08-07-2007, 06:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •