Execute shell script using Java :
Reference API :
http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Runtime.html
Download Link:
https://www.box.com/s/0gkhha9zgblmr31caa3s
import java.io.File;
public class ExecuteShellScript {
// execute shell script from java
public static void main(String[] args) {
File wd = new File("/root/Desktop/");
System.out.println("Working Directory: " +wd);
Process proc = null;
try {
proc = Runtime.getRuntime().exec("sh shell.sh", null, wd);
System.out.println("Process : "+proc);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
public class ExecuteShellScript {
// execute shell script from java
public static void main(String[] args) {
File wd = new File("/root/Desktop/");
System.out.println("Working Directory: " +wd);
Process proc = null;
try {
proc = Runtime.getRuntime().exec("sh shell.sh", null, wd);
System.out.println("Process : "+proc);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
No comments:
Post a Comment