I'm trying to execute a shell script from Java.The script is supposed to download the file from the URL using wget.Here goes my code.
public class RunShellScriptFromJava {
public static void main(String a[]) {
try {
ProcessBuilder pb = new ProcessBuilder("/bin/sh","script.sh");
Process p = pb.start();
p.waitFor();
System.out.println("Success");
} catch (Exception e) {
e.printStackTrace();
}
}
}
Content of script.sh
echo "start"
wget http://alex.smola.org/drafts/thebook.pdf
echo "end"
My Question: Is this the right way doing it?If not please point me in the right direction.It doesn't throw any exception but I see that the file is not getting downloaded.Any lead/help is appreciated.
Thanks.
PS:I have given execute permission for the script