shell中调用另一程序有返回值,此时java调用此shell无法获得程序的返回值

解决方案 »

  1.   

    没写过shell,不过shell也能想方法一样返回值吗,你可以贴出一个程序研究一下
      

  2.   

    直接终端中调用此shell 可以输出结果,使用java调用此shell无法获得输出值
    shell脚本部分代码#!/bin/shdsVal=`/info/IBM/InformationServer/Server/DSEngine/bin/dsjob -user xx -password xx 
    -server TESTDS:31539 -jobinfo dstage1 SQ_CWWJ__T_CWWJ_GLFY_SY`echo dsValexit 0
      

  3.   

    java里需要从流里去读取shell的输出,并不是shell可以直接返回 InputStream is = process.getInputStream ( ) ; 
            byte[] buffer = new byte[1024] ; 
            while ( is.read(buffer) != -1 ) { 
            result = new String (buffer) ; 
            } 
            is.close ( ) ; 
      

  4.   

    是从流中读取的,就是的不到输出值啊
     
    #!/bin/sh
     
    dsVal=`/info/IBM/InformationServer/Server/DSEngine/bin/dsjob -user xx -password xx 
    -server TESTDS:31539 -jobinfo dstage1 SQ_CWWJ__T_CWWJ_GLFY_SY`
     
    echo $dsValecho "hello world!"
     
    exit 0
     
    可以从流中换取到“hello world” 但是得不到dsVal的变量的值
      

  5.   

     Process pid = null;
     pid = Runtime.getRuntime().exec(shellCommand);
      

  6.   

    的确采用Runtime,Process。问题是inputStream获得不了值?直接运行shell文件终端可看到,而用java调用则无法获得继续up!
      

  7.   

    我遇到的问题 与此贴类似 http://bbs.csdn.net/topics/280053880 
    烦请知道的朋友指点下thanks!
      

  8.   

    String[] cmds = {"/bin/sh", "-c" , "sssss.sh"};