• Post Reply Bookmark Topic Watch Topic
  • New Topic

Firing statements into Command prompt.  RSS feed

 
Gautam Dembla
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Wanted to know if there was a way i could fire a statement into command prompt and display the results on a label((eg. c:\>ping 172.16.2.214)
and display the results of the ping response on a label(which is refreshed every 50 milliseconds)).Displaying the results can be done by capturing the response in a .txt file and maybe using a threaded IO operation and readind the response onto a label.
Purpose of me doing this is, i want to fire a logical backup of the database from the front-end, similarly restoration of the database from the front-end..
Like incase of VB 6.0, I could give a Shell command and the statement would be executed in the command prompt.
Thanx All..
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, welcome to the ranch! It's likely one of the management here will move your post down to the Java In General forum. You can solve this kind of problem with Runtime.getRuntime().exec(). To capture the output you can read from the streams provided by the Process object returned by exec.

There are some challenges - on Windows you may have to run CMD.EXE or COMMAND.EXE depending on what you want to run. On some Unix flavors the command might write output you can't get. On any environment, read the streams on separate threads to keep everything running freely.

See if that gets you started. If you get stuck, post some code down in Java In General and we'll see what we can do.
 
Gautam Dembla
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Stan,
Yeah will keep u posted abt my progress, should find a way out by tomm.
Thanx once Again
 
Jeffrey Spaulding
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In essence that would be running a system command from your servlet.
Whiiiiich is considered to be Bleargh

You might want to read this

http://www.javaalmanac.com/egs/java.lang/Exec.html

Plus

The link to "Reading Output" from the same page

J.
 
Gautam Dembla
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff,
Thanx for the input, lemme try to add the same to maybe a servlet too.. essentially i would wanna try this for a web based application!!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!