根据Runtime.getRuntime().exec(cmd)来执行xmd命令
package com.yeshun.util.process;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
public class ExecuteCmd {
public static void exec(String cmd){
try {
Process p = Runtime.getRuntime().exec(cmd);
StreamGobbler errorGobbler = new StreamGobbler(p.getErrorStream(), "ERROR");
errorGobbler.start();
StreamGobbler outGobbler = new StreamGobbler(p.getInputStream(), "STDOUT");
outGobbler.start();
p.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void execAndSave(String cmd,File file){
OutputStream os = null;
try {
Process p = Runtime.getRuntime().exec(cmd);
os = new FileOutputStream(file);
StreamGobbler errorGobbler = new StreamGobbler(p.getErrorStream(), "ERROR",os);