Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Execute commands in a sequance with RunTime.getRuntime().exec(cmd)

 
K Minev
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need to execute a sequence of commands from the Runtime and also upon the result of a command I need to be executing a different one.

Any ideas how this could be accomplished.

For example:

ping myIp
if ping is timeout
ping myIp2
else
telnet to ip 3

Any advice will be appreciated.

Thank you.
 
Siva Masilamani
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This should help you

webpage
 
K Minev
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for re-directing me to this article. I came across with it before and for some reason when i try to use the waitFor method it takes forever for the exit value to come back which indicates that I can run the next command in a sequential manner.

Any ideas how this could be accelerated or if known workaround. I need to telnet to switches and if I have to wait sunch a long time for the the username and password prompt it will be too long of a wait for my program to be efficient.

Thank you.
 
K Minev
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I didn't notice that this article has more pages to it.

Thank you for you post that gave me a good pointer.

Anybody used JConfig??? Is that a more reliable way of manipulating the JVM Runtime
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you asking about the JConfig library from Samizdat? I think that hasn't been updated for many years; I'd be hesitant to introduce it to any new projects.
 
K Minev
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I was thinking about using the JConfig library, but decided not to as you suggested.


I read the article as pointed out above, but I still don't have a clear mind on how to execute commands in sequence. I kind of got the concept for the gobblers as well. So do I need to use the output gobbler stream if I want to executed a command based on the previous one???

I would really appreciate if anyone provide with a quick code sample...something like this: command1 executed , output is enter password:, then echo myPassword and do something else.

Is that do-able at all or shall I look into an alternative approach. My alternative since I am on linux box to execute a bash script.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic