Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Process type

 
Shaik Muhammad
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am trying to execute 'ping' command in my linux machine through a java program. I am using the following method to execute the command.


The problem is that the options for the ping command are different for windows and linux.
How can i find the type of the process that is started by the exec(command) method(ie. like UNIXProcess or Win32 process)?
What are the types of processes java uses?(ie. like windows process or linux process or mac process).
How can i get their type?
Please Help
 
Christian Zillmann
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you check for the OS the code is running on and execute the ping command depending on the OS ?
 
Shaik Muhammad
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you..
I tried getting os name from runtime instance. It cannot be retrieved by runtime instance. So i used

Why runtime instance is not giving os name?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shaik Muhammad wrote:
Why runtime instance is not giving os name?


Do you mean "Why didn't they add a method to the Runtime class to tell you the name of the OS?"

Any one of us, I'm sure, can think of hundreds of methods that they might have added to the Java APIs; if all those thousands of methods were added, it would be too bloated to be useable. So although it might make sense for there to be such a method, as you can see, you can still get the information you need without it.
 
Shaik Muhammad
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply...
You mean to say that it is to reduce redundancy?
 
Campbell Ritchie
Sheriff
Posts: 48445
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried the System.getProperties method, then iterating through the Properties returned?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic