//shPath = /system/bin/sh
//shellCommand = chmod 0777 路径
public static int executeShell(String shellCommand) {
int success = 0;
try {
Process pid = null;
String[] cmd = { shPath, "-c", shellCommand };
// Shell命令を執行
pid = Runtime.getRuntime().exec(cmd);
if (pid != null) {
pid.waitFor();
} else {
}
success = 1;
} catch (Exception e) {
}
return success;
}
本文介绍了一个用于执行Shell命令的Java方法实现。该方法通过Runtime.getRuntime().exec()调用指定的Shell命令,并等待命令执行完成。代码示例展示了如何使用此方法执行chmod命令。
4462

被折叠的 条评论
为什么被折叠?



