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

4

1 回答 1

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();
}
于 2013-07-29T05:50:30.857 回答