• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

problem with Runtime getRuntime() exec(command)  RSS feed

 
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to execute "Java -version" to detect the Java version but my program behaves strangely. My code is:

The problem is that in.read() returns -1 the first time; I cannot get the results. If I try simply "Java", I do get the usage message. I am at a loss.

Your help will be greatly appreciated,

Alejandro Barrero
 
Alejandro Barrero
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just found and easy way to detect the java version: System.getProperty("java.vm.version")
 
Sheriff
Posts: 21743
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java -version writes to the error stream, not the output stream. Therefore, you should have used getErrorStream() instead of getInputStream(). Alternatively, ProcessBuilder has a method to redirect all output from stderr to stdout.

But yes, that property is soooo much easier
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!