美文网首页Java 杂谈
java代码调用shell脚本

java代码调用shell脚本

作者: 寇寇寇先森 | 来源:发表于2019-02-27 10:16 被阅读0次
    public void importDateTohive() {
            try {
                String shpath = "/data/hadoop/percisettask/2_merge_userlog.sh";
                Process ps = Runtime.getRuntime().exec(shpath);
                ps.waitFor();
    
                BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
                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();
            }
            logger.info("数据刷新成功");
        }
    

    上述代码中,下面这段就是调用shell执行的代码。

      String shpath = "/data/hadoop/percisettask/2_merge_userlog.sh";
      Process ps = Runtime.getRuntime().exec(shpath);
      ps.waitFor();
    

    注意:shpath最好写绝对路径。

    相关文章

      网友评论

        本文标题:java代码调用shell脚本

        本文链接:https://www.haomeiwen.com/subject/rzrxuqtx.html