dcsimg
Problem in executing shell script thru the process object
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Vandana_P
Posted On:   Tuesday, February 8, 2005 06:22 AM

Hi,

I am trying to run a shell script through a process object. The shell script that I call, does an installation of some software and takes approximately 30 minutes to complete. After around 15 minutes, the installation process stalls and installation doesn't continue. The java program which is creating this process object, however, does not show any signs of a problem. I have a 'waitFor' call after I do an 'exec' in the java program and it just keeps waiting.
This behaviour happens everytime and the installation always stops at the same point every time. When this shell script is launched from outside the java program, it runs fine.
Kindly help with your suggestions.

Re: Problem in executing shell script thru the process object

Posted By:   Anonymous  
Posted On:   Thursday, April 21, 2005 08:21 AM

I don't fully understand why but in order to make this work I had read to the end of the inputStream. Also make sure you close all 3 streams. See example below. You probably want to print the ErrorStream as well to see what is going on.



String[] cmd = {"/usr/bin/ksh", "/tmp/export.ksh"};



Process p = Runtime.getRuntime().exec(cmd);



BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));



String line = in.readLine();

while(line != null) {

//System.out.println(line);

line = in.readLine();
}



in.close();

p.getOutputStream().close();

p.getErrorStream().close();

Re: Problem in executing shell script thru the process object

Posted By:   sriram_thota  
Posted On:   Thursday, February 10, 2005 12:02 AM

can u please send me the piece of code.
About | Sitemap | Contact