public boolean execute(String cmd) {
String[] command = new String[] { "sh", "-c", cmd };
Runtime runtime = Runtime.getRuntime();
try {
Process process = runtime.exec(command);
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
StringBuffer pathBuf = new StringBuffer();
while ((line = in.readLine()) != null) {
pathBuf.append(line);
}
in.close();
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
其中:
cmd命令是linux命令, 如"ls"等