0

I have this code which I wrote after searching some similar forum posts in this forum:

try {
        Process p = Runtime.getRuntime().exec("cmd.exe /c start cmd.exe C:\\Users\\mm\\Documents\\NetBeansProjects\\JavaApplication1\\docs\\test.bat".split("\\s+"));
        BufferedReader reader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
        String line = null;
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }

The output is that the command prompt opens up but nothing is executed (ie the ping command contained in the batch file script). I am not sure what is missing here. Previously I tried to execute directly instead of the batch file test.bat without any success.

Please help.

Thanks

user285825
  • 475
  • 4
  • 13
  • 1
    `cmd.exe /c start cmd.exe` Huh ? Calling `cmd > start > cmd` ? why do you come up with such idea ? – Raptor Jul 29 '13 at 05:47
  • Refer this http://stackoverflow.com/questions/10685893/run-exe-file-from-java-from-file-location – Veera Jul 29 '13 at 05:48

1 Answers1

0
Try this 


try {
Runtime r = Runtime.getRuntime();
String myScript = .....
String[] cmdArray = {"xterm", "-e", myScript + " ; le_exec"};
r.exec(cmdArray).waitFor();
} catch (InterruptedException ex){
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
Shuhail Kadavath
  • 448
  • 3
  • 13