开发者社区> 问答> 正文

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-06-06 11:47:38 1861 0
1 条回答
写回答
取消 提交回答
  • 社区爱好者,专为云栖社区服务!

    1.首先确认一下:linux命令的正确性;
    2. /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:28:07
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

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