public static String executeCommand(String command, boolean flagbackground) { System.out.println("Comando a usar: "+command); String commandShell = null; String osName = System.getenv("OS"); String x = ""; if (osName.equals("Windows_NT")) { commandShell = "cmd.exe /C " + command; } else if ((osName.equals("Windows 95")) || (osName.equals("Windows 98"))) { commandShell = "start " + command; } else if (flagbackground) { commandShell = "" + command + " &"; } else { commandShell = "" + command; } try { Process proc = Runtime.getRuntime().exec(commandShell); BufferedReader brStdOut = new BufferedReader(new InputStreamReader(proc.getInputStream())); BufferedReader brStdErr = new BufferedReader(new InputStreamReader(proc.getErrorStream())); String str = "", stre = ""; while (((str = brStdOut.readLine()) != null) || (stre = brStdErr.readLine()) != null) { if (str != null) { x = x + str + "\n"; continue; } if (stre != null) { x = x + brStdErr.readLine() + "\n"; } } brStdOut.close(); brStdErr.close(); } catch (IOException eproc) { System.out.println("Error to execute the command : " + eproc); //Men.error(eproc + "", "Error En La Ejecucion"); return x; } return x; }