• Post Reply Bookmark Topic Watch Topic
  • New Topic

running batch files/scripts from java  RSS feed

 
Deyna Cegielski
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im writing a database application in java. at the moment i have to execute a batch file i made to start my mysql database server before running my program. i also have to run a batch file to stop the server

i have also been looking at modifying these batch files into VBS scripts to get rid of the command prompts that hand about on the toolbar when the server is running

is there anyway when starting my java application to execute (at a minimum) these batch files (they would be stored in the same directory) or VBS files so that the program will automatically setup the datavbase server and connect to it instead of having to manually run the server.

thanks
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a frequently asked question, try searching the forums.

You can execute batch files or executable programs using Runtime.exec(...) - look it up in the API documentation.
 
Deyna Cegielski
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for you're information tho ill have a browse through the API i had a feeling something as trivial as thing might already be implemented.

EDIT:

this is the code i am trying (and is not working)

try {
Runtime r;
Process p;
r = Runtime.getRuntime();
p = r.exec("ServerStart.bat");
}
catch(Exception e) {
System.out.println("Exception: " + e);
}

any ideas?
nothing seems to happen

also would it be possible to replace .bat with .vbs file and still get the same effect? (i have now designed to .vbs files that execute the relevant .bat files)

thanks for the help

Deyna

[ April 13, 2006: Message edited by: Deyna Cegielski ]
[ April 15, 2006: Message edited by: Deyna Cegielski ]
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at this (as mentioned in the FAQ):
JavaWorld: When Runtime.exec() won't

If you would have done a search, you would have quickly found some posts on this topic:
Loading an application from a Java Program
How to run simple windows commands through java program?
How to execute a CLI command from Java program
 
Deyna Cegielski
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, did a search and found a past post to solve my problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!