This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Execute commands in a sequance with RunTime.getRuntime().exec(cmd) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Execute commands in a sequance with RunTime.getRuntime().exec(cmd)" Watch "Execute commands in a sequance with RunTime.getRuntime().exec(cmd)" New topic
Author

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

K Minev
Greenhorn

Joined: Nov 04, 2009
Posts: 8
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

Joined: Sep 19, 2008
Posts: 385
This should help you

webpage


SCJP 6,SCWCD 5,SCBCD 5

Failure is not an option.
K Minev
Greenhorn

Joined: Nov 04, 2009
Posts: 8
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

Joined: Nov 04, 2009
Posts: 8
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
Marshal

Joined: Mar 22, 2005
Posts: 41132
    
  45
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.


Ping & DNS - my free Android networking tools app
K Minev
Greenhorn

Joined: Nov 04, 2009
Posts: 8
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.
 
wood burning stoves
 
subject: Execute commands in a sequance with RunTime.getRuntime().exec(cmd)
 
Similar Threads
DataBase Server ping
ping IP from JSP page and show result in client's command prompt
Need to execute WSH Script using JSP
Need to program for executing ping statement..
Can i Run Dos Command?