Hello,

I am working on a code which should execute any *.exe file in java. I have used a sample code which works for UI based application but do not work for command prompt applications like cmd.exe or mysql.exe. Please advise for the improvement. Thank you in advance.
Here is the code.

import java.io.*;  
public class TestExec {  
   public static void main(String[] args) {  
        try {  
            Process p = Runtime.getRuntime().exec("cmd /C dir"); //try for mysql.exe and notepad.exe it will work for notepad but not for mysql.exe  
            BufferedReader in = new BufferedReader(  
                                new InputStreamReader(p.getInputStream()));  
            String line = null;  
            while ((line = in.readLine()) != null) {  
               System.out.println(line);  
           }  
       } catch (IOException e) {  
           e.printStackTrace();  
      }  
   }  
  }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.