This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can i Run Dos Command?  RSS feed

 
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
 
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!