Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
karthik sreeram
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.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
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".
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!