• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Runtime command syntax help

 
Olivier López
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Greenhorns¡

Im trying to run a command on using the java Runtime Class, but here's my problem.
If i run this, it works perfect:




I want to run "java -version" in the CMD parameter, so i can get the java version installed on the pc, but the runtime method doesnt return anything:



Do you have any idea about why it doesnt return anything? Is the command syntax wrong?

Thanks in advanced¡
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Olivier López,

I don't think there is anything wrong in your code. The problem here is (even I don't know the reason) - java -version is not returning anything to stream.
e.g. if you simply run java instead of java -version from your code, it'll give you expected output. But I'm not aware about reason behind this behavior of java -version.

Apart from that, if you want to check java version pro grammatically, this thread might be helpful.
 
Rob Spoor
Sheriff
Pie
Posts: 20546
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A lot of programs write version and help information to the error stream instead of the output stream.
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:A lot of programs write version and help information to the error stream instead of the output stream.

Thanks Rob. It solved my doubt
Instead of it should be
 
Rob Spoor
Sheriff
Pie
Posts: 20546
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
Olivier López
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all for your responses¡
I tried using the errorStream instead of the inputStream, but it didnt make any difference.
My main goal is to know if the application is running with java 32 or 6bits, so I believe i will end solving it by using System.Property(java.home). It returns the path were java is installed, but it believe
that i can play with that path, like checking if it contains "(x86)" then the JVM being used should be 32bits, otherwise it is 64bits.
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Olivier López wrote:My main goal is to know if the application is running with java 32 or 6bits

All you need is this:I hope this helps.
 
Olivier López
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was just going to post that I tried System.getProperty("sun.arch.data.model") and it worked like a charm, thats exactly what i was looking for.

Thanks for all of your responses.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic