@tsing1226
2016-10-20T12:29:40.000000Z
字数 725
阅读 1084
java
方法
public static boolean exeShell(String command, String[] args) {
String shellPath = "";
shellPath = args[0];
String cmd = "sh " + shellPath;
Runtime run = Runtime.getRuntime();
String result = "";
BufferedReader br = null;
BufferedInputStream in = null;
try {
Process p = run.exec("cmd /c start "+shellPath);
if (p.waitFor() != 0) {
result += "没有进程号";
return false;
}
in = new BufferedInputStream(p.getInputStream());
br = new BufferedReader(new InputStreamReader(in));
String lineStr;
while ((lineStr = br.readLine()) != null) {
result += lineStr;
}
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
if (br != null) {
try {
br.close();
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return true;
}
如果调用windows下的shell脚本,请安装git来执行shell脚本。git下载地址:https://git-scm.com/download/win.