public static void executeSh(){
//linux 命令
String command = "cd .."
String[] cm = new String[]{"/bin/sh","-c",command}
//执行
Runtime.getRuntime().exec(cmd);
}
该博客展示了如何在Java中使用Runtime类执行Linux命令,例如改变当前目录。代码通过Runtime.getRuntime().exec()方法调用shell来执行命令。
public static void executeSh(){
//linux 命令
String command = "cd .."
String[] cm = new String[]{"/bin/sh","-c",command}
//执行
Runtime.getRuntime().exec(cmd);
}
2361
1614
237

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