compiler9999 has asked for the wisdom of the Perl Monks concerning the following question:

Hi PerlMonks,
Im trying to run a jar file. this jar file will output multiple question in console manner and i need to input a value in order to proceed.
e.g :
A. Choose value 1 :
1 Windows
2 Unix
Input : 2 <Enter>
B. Choose value 2 :
1 Oracle
2 DB2
Im trying :
"java -jar program.jar < abc.txt"
where abc.txt has a value of :
2
1
3
etc.
but its not working its only getting the first value. please help. thanks.

Replies are listed 'Best First'.
Re: running jar file with multiple arguments in perl
by Khen1950fx (Canon) on May 29, 2010 at 11:01 UTC
    Bringing Java into Perl would be a good place to start. Try some code, then post the results here so that we can help you.
      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.
        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.

Re: running jar file with multiple arguments in perl
by Anonymous Monk on May 29, 2010 at 09:58 UTC
    but its not working its only getting the first value. please help. thanks.

    Why don't you use the commandline interface? Its a JAR, it should have one, or you can make one real real easy. Otherwise you would have to use Expect

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: running jar file with multiple arguments in perl
by Khen1950fx (Canon) on May 30, 2010 at 22:27 UTC
    What you're trying to do with the jar is actually very trivial . Here's an example script. Note: You can use the builtin $^O to get the operating system and the diamond "<>" operator for user input:
    #!/usr/bin/perl use strict; use warnings; print "=======================================\n"; print "List of Databases: \n", "Oracle = 1\n", "DB2 = 2\n", "Some other db = 3\n", "=======================================\n"; print "Your system is: $^O\n", "Which database do you want to use: 1, 2, or 3?\n"; my $db = <>; if ($db == 1) { print "You have chosen Oracle\n"; } elsif ($db == 2) { print "You have chosen DB2\n"; } elsif ($db == 3) { print "You have chosen some other stuff\n"; } else { print "You have not chosen a database. We can't continue.\n"; }