Java 执行脚本

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;
        }
文章版权声明:除非注明,否则均为八一构原创文章,转载或复制请以超链接形式并注明出处。

发表评论

快捷回复: 表情:
AddoilApplauseBadlaughBombCoffeeFabulousFacepalmFecesFrownHeyhaInsidiousKeepFightingNoProbPigHeadShockedSinistersmileSlapSocialSweatTolaughWatermelonWittyWowYeahYellowdog
评论列表 (暂无评论,154人围观)

还没有评论,来说两句吧...

目录[+]

取消
微信二维码
微信二维码
支付宝二维码