• Post Reply Bookmark Topic Watch Topic
  • New Topic

Output problem in calling shell script from java

 
sam roychaudhury
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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
 
John Ipe
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sam,
I may be missing something, but where are you initializing fullCommand before calling exec?
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!