本帖最后由 greki 于 2010-12-20 23:06:28 编辑

解决方案 »

  1.   

    shell中有用到环境变量什么的吗?
    运行失败有什么错误提示吗?
      

  2.   


    test2.shDIRNAME=`dirname $0`
    gpg --passphrase-fd 0 --yes -o $2 -d $1  < $DIRNAME/Password.txt没有提示
      

  3.   

    /bin/sh"
    是sh 还是 ksh 或者其他的?
      

  4.   

    就两行?
    $1 $2参数没传入也不影响吗?
    chmod +x test2.sh 直接Process pcs=rt.exec("test2.sh");试试看
    难不成发生了process的死锁?
    javadoc的Process的说明的倒数第三段的最后一句话有关于死锁方面的说明Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock. 
      

  5.   

    应该是环境的问题,你看看jdk的版本,环境变量,登陆用户的时候,是不是在profile里有设置变量了
      

  6.   

    先谢谢各位。
    Linux jp_home6 2.4.21-51.EL3.customsmp #1 SMP Fri Jun 27 10:44:12 CST 2008 i686 i686 i386 GNU/Linux[admin@jp_home6 bops]$  echo $0
    /bin/bash
      

  7.   

    if (StringUtil.isBlank(cmd)) {
    throw new Exception("the arg cmd is null");
    }
    Process process = null;
    BufferedReader br = null;
    StringBuilder sb = new StringBuilder();
    String s = null;
    try {
    //TODO debug 改成linux
    process = Runtime.getRuntime().exec(cmd); 
    //process = Runtime.getRuntime().exec(new String[] { "/bin/sh", "-c", cmd });
    //process = Runtime.getRuntime().exec("cmd /C start /min "+ cmd );
    log.error("====cmd===start====   "+ cmd);
    br = new BufferedReader(new InputStreamReader(process.getInputStream()));
    while ((s = br.readLine()) != null) {
    sb.append(s).append("\n");
    }
    log.error("====cmd===end=======================   ");
    log.error("====result:======="+sb.toString());
    //if(doSynchrony){
    //process.wait();
    //}
    return sb.toString();
    // }catch(InterruptedException e){
    // log.error("execute cmd error,processes was interrupted, cmd: " + cmd);
    // throw e;
    }
    catch(Exception e){
    log.error(e);
    throw e;
    }
    finally {
    if (process != null) {
    process.destroy();
    }
    process = null;
    if (br != null) {
    try {
    br.close();
    } catch (Exception e) {
    throw e;
    }
    br = null;
    }
    }
      

  8.   

    这个阻塞判断不了
    执行后return sb.toString();返回的信息是什么?
      

  9.   

    没有返回
    /usr/local/bin/gpg --no-tty --passphrase-fd 0 --yes -o $2 -d $1  < /home/admin/bops/Password.txt 2> /tmp/temp.txt现在解决了。C环境找不到/dev/tty运行的时候加了 --no-tty 谢谢各位了