This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Output problem in calling shell script from java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Output problem in calling shell script from java" Watch "Output problem in calling shell script from java" New topic
Author

Output problem in calling shell script from java

sam roychaudhury
Greenhorn

Joined: Feb 12, 2004
Posts: 1
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

Joined: Dec 29, 2003
Posts: 25
Hi Sam,
I may be missing something, but where are you initializing fullCommand before calling exec?
 
Don't get me started about those stupid light bulbs.
 
subject: Output problem in calling shell script from java
 
Similar Threads
running a batch file from java
How to connect to an UNIX server from Java application
How to invoke 'exe' in JSP
Problem executing an exe executable!
problem calling isql or osql from java