• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Output problem in calling shell script from java

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sam
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sam,
I may be missing something, but where are you initializing fullCommand before calling exec?
reply
    Bookmark Topic Watch Topic
  • New Topic