I want to execute an array of commands in my dir. When I hit cd C:/Users/Lennart/sciebo/Semster 2/Info/RepoCreator/Abgabe 4
into the command line it works fine.
But when I execute the follwing code I am getting a FileNotFoundException, because "System cannot find the file specified".
Runtime.getRuntime().exec(getCMDs());
...
private static String[] getCMDs() {
String cd = "cd C:/Users/Lennart/sciebo/Semster 2/Info/RepoCreator/Abgabe " + index;
// String cd = "cd " + path + "/Abgabe " + index;
String init = "git init";
String add = "git add .";
String commit = "git commit -m \"Inital commit\"";
return new String[] {cd, init, add, commit};
}
I tried to use Runtime.getRuntime().exec(getCMDs(), null, file)
with the required changes. File was File file = new File("C:/Users/Lennart/sciebo/Semster 2/Info/RepoCreator/Abgabe 4");
Loading the file was not a problem and also System.out.println(file.exists()); was true, but executing the array led to the same error.
Thank you
EDIT:
Yes, I tried the overloaded methode as described above. Here is the code:
File file = new File(path + "/RepoCreator/Abgabe 4");
System.out.println(file.exists());
try {
Runtime.getRuntime().exec(getCMDs(), null, file);
...
private static String[] getCMDs() {
String init = "git init";
String add = "git add .";
String commit = "git commit -m \"Inital commit\"";
return new String[] {init, add, commit};
}
Unfortunally this does not make a difference.