• Post Reply Bookmark Topic Watch Topic
  • New Topic

can we run a Batch file from our java program  RSS feed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want to know how to run a .bat file or .cmd file by using a java program,my batch file may consist of some MS DOS commands like

dir
cd c:\kkk\.........
help
javac


some more like this .........

please reply me if you know about it.
 
author and iconoclast
Sheriff
Posts: 24219
40
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

See the family of methods named "exec()" in the java.lang.Runtime class; they allow you to run external programs from Java. You'll need to run the command shell with the batch file as an argument, like "cmd.exe /c batch.bat".
 
I love a woman who dresses in stainless steel ... and carries tiny ads:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!