• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can i Run Dos Command?  RSS feed

 
sandeep java
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,


Is it possible to run dos commands using java code. If yes can anyone tell me the code how to do it



Sandeep
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

The static "exec()" methods in the java.lang.Runtime class let you run external programs. Be careful, though -- some "DOS commands" are programs, and some are actually build into the CMD.EXE shell program. To run these latter commands (DEL, say, or COPY) you need to use Runtime.exec() to execute CMD.EXE, and get it to execute the commands (not that there's any reason to ever run the DEL or COPY commands, because you can do the equivalent operations in Java just as easily.)
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't post the same question to multiple forums here at the ranch. I just deleted another copy of this thread I found in our "Beginner" forum. See here for an explanation.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!