• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to run dos batch file from java program

 
James Ajewole
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
How can i run a dos batch command from a java program. For example i want to run a dos batch file after executing a java program, and i want to initiate the dos batch command from the java program. thanks
james
 
John Ipe
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

what did you mean by "initiate the dos batch command"?
regards
 
John Ipe
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you mean you want to pass parameters to the batch file from the java pgm, you could append those as Strings after the batch file name:

and your batch file would read param1 and param2 with %1 and %2 respectively. is this what you needed?
regards
 
James Ajewole
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks john, i'll try out the command.
 
James Ajewole
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi john,
unfortunately it didnt work. I tried to execute a simple bat file to echo something but i never saw anything echoed on the screen.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It won't go to the screen. It will go to the process's standard output, which is available from the Process object created by Runtime.exec(). You call getInputStream() on the Process, and, if you want, you read data out of the InputStream and display it on the console; something like
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic