Here you can find the source of execWindowsCommand(String cmd)
Parameter | Description |
---|---|
cmd | a parameter |
public static boolean execWindowsCommand(String cmd)
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { /**/*ww w .ja v a 2s .c om*/ * * @param cmd * @return */ public static boolean execWindowsCommand(String cmd) { if (cmd.contains("echo")) { String[] cmdParts = cmd.split(" > "); // if (CommonConstants.OUTPUT) System.out.println("cmd0 : " + cmdParts[0]); // if (CommonConstants.OUTPUT) System.out.println("cmd1 : " + cmdParts[1]); String fileContent = cmdParts[0].substring(5); try { { final java.io.PrintWriter file = new java.io.PrintWriter(cmdParts[1]); file.println(fileContent); file.close(); } return true; } catch (Exception err) { err.printStackTrace(); return false; } } else { try { String[] execCmd = { cmd }; String line; Process p = Runtime.getRuntime().exec(execCmd); BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); while ((line = input.readLine()) != null) { System.out.println(line); } input.close(); return true; } catch (Exception err) { err.printStackTrace(); return false; } } } }