开发者社区> 问答> 正文

java执行linux++++

java.io.IOException: Cannot run program "cat /opt/parser/standalone/log/server.log.2015-09-24|grep ''waybillNo':'229412652241''|grep ''opOrgCode':'226000''|grep ''opCode':'795''": error=2, No such file or directory
执行这条命令报错了,求大神指教

展开
收起
杨冬芳 2016-07-13 17:44:40 1999 0
1 条回答
写回答
取消 提交回答
  • IT从业

    1.首先确认一下:linux命令的正确性;

    1. /opt/parser/standalone/log/server.log.2015-09-24等 中是否有需要转义的特殊字符。
      用下面的代码测试时正确的
     Runtime runtime = Runtime.getRuntime();
            Process process = null;
            BufferedReader reader = null;
            String command = "cat /opt/test.txt |grep \"test\"";
            try {
                process = runtime.exec(command);
                int retCode = process.waitFor();
                reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
                System.out.println("oooo" + reader.readLine());
            }
    2019-07-17 19:55:56
    赞同 展开评论 打赏
问答分类:
问答地址:
相关产品:
问答排行榜
最热
最新

相关电子书

更多
Alibaba Cloud Linux 3 发布 立即下载
ECS系统指南之Linux系统诊断 立即下载
ECS运维指南 之 Linux系统诊断 立即下载