I am in some trouble. I am trying to force create a folder using bash command through java code in linux server. My code is as followes-
String command = "/root/new_scripts/makedir.sh /webroot/Own";
try {
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(command);
return "true";
} catch (Exception ex) {
return ex.toString();
}
and the makedir.sh files contains
#!/bin/bash
mkdir $1
But it cannt create a directory.
And also try to create a directory just using java code is as following-
String s = null;
try {
Process p = Runtime.getRuntime().exec("mkdir /webroot/Own");
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
// read the output from the command
System.out.println("\n\n\nHere is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
} catch (Exception ex) {
System.out.println("\n\n\nexception happened - here's what I know: ");
ex.printStackTrace();
}
But it gives me the following error-
Here is the standard output of the command:
Here is the standard error of the command (if any):
mkdir: cannot create directory `/webroot/Own': Permission denied