How to run shell script from java
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   satya_g
Posted On:   Thursday, February 7, 2002 10:19 AM

hi friends, For running shell script from java program i am using following code. public class shj { public static void main(String a[]) { try { Process p= Runtime.getRuntime().exec("sh x.sh"); } catch(Exception e) { System.out.println(e.getMessage()); } System.out.println("done"); } } But i am not getting any output from the shell script. Please help me in running shell script from java program. Thanks Satya    More>>

hi friends,

For running shell script from java program i am using following code.


public class shj
{
public static void main(String a[])
{

try
{
Process p= Runtime.getRuntime().exec("sh x.sh");

}
catch(Exception e)
{
System.out.println(e.getMessage());
}
System.out.println("done");
}
}

But i am not getting any output from the shell script.

Please help me in running shell script from java program.

Thanks
Satya

   <<Less

Re: How to run shell script from java

Posted By:   amit_anand  
Posted On:   Thursday, February 7, 2002 12:10 PM

Try this

Process p = r.exec("Name of your shell script");

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

You can use br.readLine() to read the process output.

Hope this helps.

Regards

Re: How to run shell script from java

Posted By:   Christopher_Schultz  
Posted On:   Thursday, February 7, 2002 10:44 AM

Once you create a process, you will have to manage its output streams (both stdout and stderr). Otherwise, you will not see any output, and the process may block waiting for you to read its output.



-chris
About | Sitemap | Contact