-1

Lets suppose I have a listener for a Button

public class Visualizer1 implements ActionListener {
        public void actionPerformed(ActionEvent a) {
            try {
                Runtime rt2 = Runtime.getRuntime();
                Process p = rt2.exec("visualizer/vis1.exe");
                InputStream in = p.getInputStream();
                OutputStream out = p.getOutputStream();
                InputStream err = p.getErrorStream();

                p.destroy();
            } catch (Exception exc) {/* handle exception */
            }

the "vis1.exe" will execute without any problem and it will open up but if I have an application with a ".bat" extension like if it was(vis1.bat), it won't open up. Note: .bat extension is an executable file

  • Read this: http://stackoverflow.com/questions/615948/how-do-i-run-a-batch-file-from-my-java-application – Obicere Apr 28 '14 at 06:02
  • 1
    try to start via "c:\windows\system32\cmd.exe your.bat" or maybe "%comspec% your.bat" where %comspec% is an environment variable that should contain the path to cmd.exe that is used for .bat execution – Dodge Apr 28 '14 at 06:03
  • Please code it for me. my "vis1" file lies in folder called "home" – Saad Zaheer Apr 28 '14 at 06:24

3 Answers3

1

Try this..

Runtime.getRuntime().exec("cmd /c start vis1.bat");
niiraj874u
  • 2,180
  • 1
  • 12
  • 19
0

a .bat isnt an executable file.

"A .BAT (short for "batch") file is a plain text file that contains a series of Windows commands. An .EXE (short for "executable") file is a binary file that contains much more complex executable binary code."

http://www.fileinfo.com/help/bat_vs_exe_files

Vince
  • 14,470
  • 7
  • 39
  • 84
0

Have you gone through previous threads on same issue on stackoverflow.com?

Have a look at followings:

Community
  • 1
  • 1
Balwinder Singh
  • 2,272
  • 5
  • 23
  • 34