//java执行命令行
public static void runCmds(String cmd) throws IOException, InterruptedException
{
String cmds[] = {"/bin/bash", "-c", sudoCmd + cmd};
Process process = Runtime.getRuntime().exec(cmds);
InputStreamReader ir = new InputStreamReader(process.getInputStream());
ir.close();
}
//java执行命令行 root权限
public static void runCmdsjy(String cmd) throws IOException, InterruptedException
{
String cmds[] = {"sh", "-c", cmd};
Process process = Runtime.getRuntime().exec(cmds);
InputStreamReader ir = new InputStreamReader(process.getInputStream());
ir.close();
}
//通道
protected static String sudoCmd = "echo \"jh2pass\" | sudo -S ";
java执行linux命令行
最新推荐文章于 2023-12-13 09:32:24 发布