IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

Shell Script from java service output problem

  • 1.  Shell Script from java service output problem

    Posted Fri February 13, 2004 03:45 AM

    Hi,
    I’m calling the following shell script locally from a java service in webMethods.


    #!/bin/ksh
    abc.sh $1
    echo $?


    This script will call another script abc.sh which returns a flag of value 0/1/2/3 and I am echoing the return value.

    When I run this from unix prompt I get a return value 2(which looks ok) but when i run the java service I get the output as 1. Can anyone tell me what is going wrong ?

    My java code looks like this:

    #########################################

    IDataCursor idcPipeline = pipeline.getCursor();
    String line = null;
    Vector ssOut = new Vector();
    String fullCommand ;
    String successFlag = “false”;
    String scriptOutput = null ;

    try {
    Process child = Runtime.getRuntime().exec(fullCommand);
    int exitValue = child.waitFor();
    if(exitValue==0){
    InputStream iStm = child.getInputStream();
    InputStreamReader isReader = new InputStreamReader(iStm);
    BufferedReader br = new BufferedReader(isReader);
    while ( (line = br.readLine()) != null)
    ssOut.add(line);
    int size = ssOut.size();
    scriptOutput = ssOut.elementAt(size-2).toString();
    successFlag=“true”;
    }else{
    exitvalue = exitValue;
    successFlag=“false”;
    }
    }
    catch (Throwable e) {
    successFlag=“false”;
    }
    finally{

    idcPipeline.insertAfter(“successFlag”, successFlag); idcPipeline.insertAfter(“outFlag”, outs);
    idcPipeline.insertAfter(“scriptOutput”, ssOut);
    //Destroy the cursor
    idcPipeline.destroy();
    }
    #########################################

    Will appreciate if anyone can suggest something to solve my problem.

    Thanks


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 2.  RE: Shell Script from java service output problem

    Posted Tue February 17, 2004 04:37 PM

    HI,
    May be you should use child.getOutputStream instead of getInputStream. you are trying to get the output from the shell script right?

    Thanks,
    Hari.


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services