tags:

views:

132

answers:

4

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
If this is how you do it _using perl_, how would you do it without perl?
Evan Carroll
+2  A: 

in a perl script,

@args = ("java", "-version");
system(@args) == 0
    or die "system @args failed: $?"

or rather simply,

system("java -version");
phoenix24
phoenix has already answered your question.
Vinothbabu
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
@Bill: you are correct. I'm not sure why the OP accepted this answer without testing it first.
Ether
+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
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
`export` run from a `system()` call will not remain in effect after it ends.
Hasturkun