如题:     java 执行shell 脚本 返回 find的内容~~     find.sh 内容为:    #!/bin/sh    source /etc/profile;    find . -name "*2013-04-14*" |xargs grep cn="[email protected]"
   直接执行脚本,可以打印出数据。但是在JAVA代码中:    Process  child=Runtime.getRuntime().exec(pathshell+"/find.sh");    final InputStream inputStream = child.getInputStream();
    final BufferedReader brOut = new BufferedReader(new InputStreamReader(inputStream));    却没有内容~~  这是为什么?要怎么才能把find 的内容获取到呢???
Java脚本shell行业数据

解决方案 »

  1.   

    你确定find.sh 有数据返回。
    直接用一个命令试一下。shell脚本本人没有尝试过,但一条命令返回数据是肯定可以读到。
    理论上shell脚本应该是一样的。
    find /etc/profile -name "*2013-04-14*" |xargs grep cn="[email protected]"
      

  2.   

    我用了echo 打印,可以打印出内容,但是无返回内容。。=。=!~ 但是如果我直接用 echo打印一堆字母 例如 “qweeqewq” Java 就可以获取到~  =。=!~  郁闷
      

  3.   

    这是命令 又不是函数肯定没返回值啊 你可以把查到的东西写到一个文件里 在读取 find . -name "*2013-04-14*" |xargs grep cn="[email protected]" > a.txt 好像是这样的
      

  4.   

    Runtime rt = Runtime.getRuntime();
    Process p = rt.exec(pathshell+"/find.sh");
    BufferedReader in = null;
    {
    in = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String str = null;
    while ((str = in.readLine()) != null) {
    System.out.println(str);
    }
    }
    这样试试