/* * Grundlage ist dieser Artikel: * http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html * Diese Klasse ruft die Windows Kommandozeile mit Parameterstring auf. */ public class WindowsExec { public void execute(String commandline) { try { String osName = System.getProperty("os.name"); //System.out.println("osName: " + osName); String[] cmd = new String[3]; if (osName.equals("Windows NT") | osName.equals("Windows XP")) { cmd[0] = "cmd.exe"; cmd[1] = "/C"; cmd[2] = commandline; } else if (osName.equals("Windows 95") | osName.equals("Windows 98")) { cmd[0] = "command.com"; cmd[1] = "/C"; cmd[2] = commandline; } Runtime rt = Runtime.getRuntime(); System.out.println("Executing: " + cmd[0] + " " + cmd[1] + " " + cmd[2]); Process proc = rt.exec(cmd); // any error message? StreamFetcher errorFetcher = new StreamFetcher(proc.getErrorStream(), " ERROR> "); // any output? StreamFetcher outputFetcher = new StreamFetcher(proc.getInputStream(), " OUTPUT> "); // kick them off errorFetcher.start(); outputFetcher.start(); // any error??? int exitVal = proc.waitFor(); //int exitVal = proc.exitValue(); System.out.println("ExitValue: " + exitVal); } catch (Throwable t) { t.printStackTrace(); } } }