How do I find out which version of Java I am using Perl programming and using that execute some jar file based on that?
A:
"java -version" will show you the version you are using.
"perl -v" will show you the version of Perl you are using.
decompiled
2010-05-10 15:29:02
If this is how you do it _using perl_, how would you do it without perl?
Evan Carroll
2010-05-10 15:52:31
+2
A:
in a perl script,
@args = ("java", "-version");
system(@args) == 0
or die "system @args failed: $?"
or rather simply,
system("java -version");
phoenix24
2010-05-10 15:31:58
Won't this just print the version out to the console without capturing it? I'm quite rusty at Perl, but I think if he wants to use the result he'll need to capture it with backticks.
Bill the Lizard
2010-05-10 15:46:29
@Bill: you are correct. I'm not sure why the OP accepted this answer without testing it first.
Ether
2010-05-10 16:41:06
+4
A:
You can capture the Java version from a Perl script using backticks.
$version = `java -version`;
Also see: How can I capture STDERR from an external command? for more alternatives than you can shake a stick at.
Bill the Lizard
2010-05-10 15:35:03
A:
Use the System command...
system("java -version");
If you are going to export a new Java
system('export PATH=/usr/java1.6/bin:$PATH');
Vinothbabu
2010-05-10 15:42:46
`export` run from a `system()` call will not remain in effect after it ends.
Hasturkun
2010-05-10 16:01:12