0

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();  
      }  
   }  
  }

Edited by Nick Evan: Fixed formatting

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Salem
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.