粪怒的石头 2016-11-23 09:26 采纳率: 50%
浏览 3800

调用Runtime.getRuntime().exec(cmds)方法使用linux的tail命令

有没有熟悉java的runtime的么?通过调用Runtime.getRuntime().exec(cmds)方法使用linux的tail命令去拿回的inputstream流的长度是有限制的么? 为什么我每次它只能最大给我传回来64k。。

 String cmd = null;
            if (logLineCount > 0) {
                cmd = "tail -n " + logLineCount + " " + filePath;
            } else {
                cmd = "cat " + filePath;
            }

            String[] cmds = new String[] {"/bin/sh", "-c", cmd};
            Process process = null;
            process = Runtime.getRuntime().exec(cmds);
            logger.debug("process: " + process.toString());
            if (process != null) {
                    InputStream in = process.getInputStream();
                    int size = in.available();
                    byte[] buffer = new byte[size];
                    in.read(buffer);
                    in.close();
                    result = new String(buffer, "UTF-8");
            }
  • 写回答

1条回答 默认 最新

  • threenewbee 2016-11-23 16:09
    关注

    if (process != null) {
    process.waitFor();
    InputStream in = process.getInputStream();
    ...

    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)