Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store executable jar output in a variable in Perl

Tags:

jar

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");

system(@args);

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

like image 233
john Avatar asked Mar 25 '26 14:03

john


1 Answers

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

like image 104
mkHun Avatar answered Mar 27 '26 13:03

mkHun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!