Here is an example shows how to execute the shell scripts from java programs.
If you want to execute the below program set the java path in Unix environment.
export PATH=$PATH:/usr/jdk1.5.0/bin
export CLASSPATH=$CLASSPATH:/usr/jdk1.5.0/bin
create a shell script like shellscript.sh
#!/bin/bash
clear
echo "Good morning, world."
then change the permission for this script.if you execute the shell script you need execute permission.
chmod 777 shellscript.sh
try
./shellscript.sh
From java program
import java.io.IOException;
public class JavaScript {
public static void main(String[] args) {
try {
Runtime.getRuntime().exec("/root/shellscript.sh");
System.out.println("Working Fine");
} catch (IOException e) {
e.printStackTrace();
}
}
}
0 Comments:
Post a Comment