john john - 1 year ago 49
Perl Question

Store executable jar output in a variable in Perl

I need the retrieve the output of a Java program and store it in a Perl variable so that i'll be able to use split function. I am getting the java output using,

my @args = ("java", "-jar", "first.jar");


But how to convert this
variable (string) so that i can split the output from the string.

Answer Source

I hope you need to store the output of the jar file. So use backtick instead of system. Try to know difference between system and Backtick / qx

my @args = ("java", "-jar", "first.jar");

my $result = `@args`;

my @ans = split(" ",$result);

print "$ans[0] $ans[1]";

suppose your result is xyz abc. $ans[0] store the xyz and $ans[1] store the abc

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download