in reply to Re: running jar file with multiple arguments in perl
in thread running jar file with multiple arguments in perl

Hi Khen, Ive already posted here what i have done so far : Here it is :
system("java -jar program.jar < abc.txt") and
OPEN PIPE, "|java -jar program.jar"; open FH, /abc.txt while (my $res = <FH>) print PIPE "$res"; close FH; close PIPE;

but not working as expected.
Thanks.

Replies are listed 'Best First'.
Re^3: running jar file with multiple arguments in perl
by Corion (Patriarch) on May 29, 2010 at 13:54 UTC
    OPEN PIPE, "|java -jar program.jar";

    That's barely valid Perl code. If you get error messages, tell us those error messages. When I run your Perl code, I get the following error message:

    Useless use of a constant in void context at -e line 1. Can't locate object method "OPEN" via package "PIPE" (perhaps you forg +ot to load "PIPE"?) at -e line 1.

    This is because your code makes little sense without further context. I highly doubt that your program is even launching your jar file for you at all.

      Hi Corion,
      Sorry i thought khen was the one answering. Anyways, this is the code i am not sure if i have missed something, i cannot try the code at home its in the office as far as i remember it is working. To simplify the code it should be like this :
      open PIPE, "| java -jar java_program.jar"; print PIPE "$string"; close(PIPE);

      hope you are now convinced i have code. and not pretending i have. Thanks anyway.

        This is not code that could ever run in Perl. It helps us to help you better if you show us the exact, minimal code you have that exhibits the problem. What you've shown so far cannot be that code because it does not run.

      Hi Khen, Its actually running, the problem is it will only get the first value of the abc.txt. The jar file actually able to run. My problem is i don'tknow how to pass the second value.
      The output of the jar file is as below :
      e.g :
      A. Choose value 1 :
      1 Windows
      2 Unix
      Input : 2 <Enter>
      B. Choose value 2 :
      1 Oracle
      2 DB2
      Input : 1 <Enter>

        I'm not Khen1950fx, and the code you have posted is not valid Perl. If you have code that compiles and "works", post that code. If you don't have code, don't claim that you have code.

        You will likely have to use Expect or find out how to automate reading from Standard Input in Java.