多的不说,直接上代码:
public String exec(String command) {
StringBuffer output = new StringBuffer();Log.d("exec", command);
try {
Process process = Runtime.getRuntime().exec(command);
DataInputStream stdout = new DataInputStream(process.getInputStream());
String line;
while ((line = stdout.readLine()) != null) {
output.append(line).append('\n');
}
process.waitFor();
} catch (Exception e) {
output.append('\n').append(e.toString());
}
return output.toString();
}
经过验证,此方法在1.6、2.0下都是有效的。