File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes DOS Window Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "DOS Window" Watch "DOS Window" New topic

DOS Window

Mathew Kuruvilla
Ranch Hand

Joined: Nov 27, 2001
Posts: 135
How can I launch a dos window and execute a batch file from the actionPerformed method of an ActionListener?
Ulas Ergin
Ranch Hand

Joined: Oct 10, 2002
Posts: 77
you might want to investigate Runtime.exec
Mathew Kuruvilla
Ranch Hand

Joined: Nov 27, 2001
Posts: 135
Runtime.exec worked but the way that I did it for DOS and UNIX was different.
Runtime r = Runtime.getRuntime();
if (System.getProperty("").startsWith("Windows"))
sb.append("cmd /C start ").append(instaldir).append("\\MAT\\Kuruvi\\lla\\bin\\runSimulator.bat -p ").append(port);
sb.append("xterm -e ksh ").append(instaldir).append("/MAT/Kuruvi/lla/bin/ -p ").append(port);


The ksh script for unix did not begin with a #! (hashbang) so I had to begin the command with 'ksh'. If the script had had a hashbang at the beginning, maybe I could have run the script straight away.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: DOS Window