Java调用系统脚本

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cpp1781089410/article/details/81188553

1.调用系统命令

public static void main(String[] args) throws Exception {

        try {
            //执行脚本语句
            //Process p = Runtime.getRuntime().exec("nslookup app.xidian.com.cn");
            String shpath = "/home/eplusing/demo.sh";
            //执行脚本文件
            Process p = Runtime.getRuntime().exec(shpath);
            p.waitFor();
            BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream(), "GB2312"));
            StringBuffer sb = new StringBuffer();
            String line;
            while ((line = br.readLine()) != null) {
                sb.append(line).append("\n");
            }
            String result = sb.toString();
            System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

2.调用本地方法

猜你喜欢

转载自blog.csdn.net/cpp1781089410/article/details/81188553