1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Rep Power

    How to call java from perl


    i have a perl cgi script, and i wish to pass one value into a java program, have the program then do something and pass it back. i was wondering how i can go about this without using inline and where i need to keep the java program - if not in the cgi-bin? there are two java programs that i want to call in different if loops in perl. is that also possible? i would appreciate any help. thanks!
  2. #2
  3. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Shanghai, An tSín
    Rep Power
    Firing up a JVM twice for every CGI request (as well as the Perl interpreter) is going to be very slow, so I would consider a different approach.

    However, to answer your question...

    Firstly, I'm not sure what you mean by "without using inline".

    You can run an external command in Perl (and grab the output) using backticks, as follows:
    my $output = `java -cp classpath ClassName param`;
    Here, param is the value you want to pass to your Java program, which will be in the arguments array that's passed to your main method. From your Java program, if you print to standard output, this will get picked up and saved in your $output variable in Perl.

IMN logo majestic logo threadwatch logo seochat tools logo