Java code to Execute Shell script

Program to Execute Shell script / batch file using Java



In normal we Execute Java program using shell script . But here we are creating java program to execute shell script / batch file.
This can be done by using executing the system process using "Process proc = Runtime.getRuntime().exec("./execute_shell_using_java.sh");". This is a simple program that will just execute the sh/ shell script file execute_shell_using_java.sh.
Note: sh file will not run in windows and bat file will not run in linux

public class Sh
{
public static void main(String[] args)
{
try
{
Process proc = Runtime.getRuntime().exec("./execute_shell_using_java.sh");
System.out.println("Print Test Line.");
}
catch (Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}


Related Topic Execute java program using shell script
Struts FAQs
PHP Programming Best Practices
What are all Common use of SSH for UNIX and Linux systems
How to Organize Android Build System Project Structure

nScraps.com 2011   Privacy Policy  Terms of Service  Feedback