-1

I need to pass two params in a java file similar as I pass from command line.

Something like

$ENV{classpath} = ".\\my.jar;$ENV{classpath}";
system("$ENV{JAVA_HOME}\\bin\\java com.myclass  param1  param2"  );

how can i achieve this in a perl script?

smriti
  • 1,124
  • 5
  • 14
  • 35

1 Answers1

2

I don't have access to my work system still let me give it a try. It should work for you.

my $cpJava=" -cp /your/classpath";
my $myClass="your class name";
my $runMe="Java path ".$cpJava." ".$myClass." ".join(' ', @ARGV);

@ARGV will have all your parameters. Learn more about join from here.

Then use system:

system($runMe);

Hope it would work for you.

Helios
  • 851
  • 2
  • 7
  • 22
  • Wow Nik. Thank you soo much. So if i want to pass two params i can @ARGV = ("param1", "param2"); and pass.. thanks – smriti Jan 20 '14 at 10:12
  • But what @Nik has given you is, effectively, no different from what you had originally. He's just building up the string before passing it to `system`. – Dave Cross Jan 20 '14 at 13:46
  • `my $runMe = "Java path $cpJava $myClass @ARGV";` - this does the same thing too. Perl interpolates variables in a double-quoted string. – Dave Cross Jan 20 '14 at 13:48