в беда съм. Опитвам се да създам принудително папка с помощта на команда bash чрез java код в linux сървър. Моят код е както следва -
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();
}
и файловете makedir.sh съдържат
#!/bin/bash
mkdir $1
Но не може да създаде директория.
И също така опитайте да създадете директория само с помощта на java код, както следва-
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();
}
Но ми дава следната грешка-
Ето стандартния изход на командата:
Ето стандартната грешка на командата (ако има такава):
mkdir: не може да създаде директория `/webroot/Own': разрешението е отказано
mkdir /webroot/v3custompritom
. - person dma_k   schedule 06.12.2011strace
-ing вашата Java VM; ще разбереш защо твоетоmkdir
се проваля. - person Basile Starynkevitch   schedule 06.12.2011