Olá, galera estou precisando executar um .bat (comandos do DOS) no Windows XP a partir de uma classe em Java
e já tentei todos os códigos abaixo, mas não conseguí executar o file.bat que está no c:.
[code]import java.io.BufferedReader;
import java.io.InputStreamReader;
public class ExecutaBat {
/* public static void main(String[] args) {
Runtime run = Runtime.getRuntime();
try {
run.exec(“c:\file.bat”);
} catch (Exception e) {
e.printStackTrace();
}
}
*/
/* public static void main(String[] args) {
try {
Process process = Runtime.getRuntime().exec(“c:\file.bat”);
} catch (IOException e) {
e.printStackTrace();
}
}*/
/* public static void main(String[] args) throws IOException {
Runtime.getRuntime().exec(“cmd /c c:\file.bat”);
}*/
/*public static void main(String[] args) {
Runtime run = Runtime.getRuntime();
try {
run.exec("cmd start /c C:/file.bat");
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("FINISHED");
}*/
/* public static void main(String[] argv) throws Exception {
Runtime.getRuntime().exec(“cmd /c c:\file.bat”);
Thread.sleep(2);
} */
/* public static void main(String[] args) {
Runtime runtime = Runtime.getRuntime();
String[] cmd = { “cmd”, “/c”, “c:\file.bat” };
try {
Process p = runtime.exec(cmd);
BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = b.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
}
}*/
}[/code]