Possible Duplicate:
Java code to execute a .sh file
I write the code in a .sh file with one parameter in /root/new_scripts/setpermission.sh and run it: setpermission.sh contains:
chmod 777 $1
It executed successfully from linux console by typing /root/new_scripts/setpermission.sh location . But when i tried to run it using java code using: Java full code:
String fileLocation = BASE_DIR + domain + SUB_DIR_CAKE + fileName;
File newFile = new File(fileLocation);
System.out.println("Permission file location: " + fileLocation);
if(newFile.exists()) {
String command;
String[] commandArray;
command = "/root/new_scripts/setpermission.sh";
File commandFile = new File(command);
if(commandFile.exists()) {
System.out.println("\n\n\n\n\nFILE EXISTS");
} else {
System.out.println("\n\n\n\n\nFILE NOT EXISTS");
}
commandArray = new String[]{"/bin/sh", command, newFile.toString()};
try {
Process p = Runtime.getRuntime().exec(commandArray);
return "HERE OK";
} catch (Exception e) {
e.printStackTrace();
return e.getMessage();
}
} else {
return "file not exists";
}
and it returns HERE OK