dcsimg
problem in executing shell script using java
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   srinivas_saranu
Posted On:   Wednesday, September 11, 2002 02:02 AM

hi i want to execute a shell script file (example:-source.sh) in linux operating system using java program. The code i have written is as follows class fileExecute{ public static void main(String args[]){ Runtime r=Runtime.getRuntime(); Process p=null; String [] cmd={"/bin/sh","-c","source.sh"}; try{ p=r.exec(cmd); p.waitFor(); } catch(Exception e){ System.out.println(e); } System.out.println("returned:"+p.exitValue()); } } After running this program the shell script is not executing...also iam not getting any errors... we are using redh   More>>

hi


i want to execute a shell script file
(example:-source.sh) in linux operating system
using java program.



The code i have written is as follows


			
class fileExecute{
public static void main(String args[]){
Runtime r=Runtime.getRuntime();
Process p=null;
String [] cmd={"/bin/sh","-c","source.sh"};
try{
p=r.exec(cmd);
p.waitFor();
}
catch(Exception e){
System.out.println(e);
}
System.out.println("returned:"+p.exitValue());
}
}

After running this program the shell script is not executing...also iam not getting any errors...


we are using redhat linux 7.1 and jdk 1.3


srinivas

   <<Less

Re: problem in executing shell script using java

Posted By:   Stephen_Ostermiller  
Posted On:   Monday, September 16, 2002 12:26 PM

If your script has output on standard output or standard error streams, you should get those streams from the process (p) on the java side and read from them. It is possible that a buffer is filling up and your process never completes because of it.

Re: problem in executing shell script using java

Posted By:   Simon_Ablett  
Posted On:   Wednesday, September 11, 2002 02:28 AM

Try adding a first line of '#!/bin/sh' to the file 'source.sh' and then simply invoke this file rather than invoking the shell itself. Hope that this works.

Regards.
About | Sitemap | Contact