Runtime.getRuntime().exec(“文件的位置”)

        try {
            Runtime.getRuntime().exec("文件名");
        } catch (IOException e) {
            e.printStackTrace();
        }

脚本

        String res = "";
        List<String> processList = new ArrayList<String>();
        try {
            Process process = Runtime.getRuntime().exec("/home/java/jar/restart12347.sh");
            BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line = "";
            while ((line = input.readLine()) != null) {
                processList.add(line);
            }
            input.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        for (String line : processList) {
            System.out.println(line);
            res = res + line;
        }

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注