Windows can not find & ldquo; run.bat & rdquo; file, from the processing

advertisements

I am trying to run a bat file from Processing. But the program does not find it even though the bat file is inside the folder of the Processing file.

My code is:

Runtime r = Runtime.getRuntime();
Process p1;
try {
  p1 = r.exec("cmd /c start run.bat");
}
catch(Exception c) {
}

The error that appears when I run Processing is: "Windows can not find "run.bat" file. Make sure the name is spelled correctly and try again."

Can you help me?


Since you are running the start command from cmd instead of directly from Java, you have to specify the full path. You can get the path to your Java project folder with System.getProperty("user.dir"). If the batch file is in the root of your project folder, your code would look like this:

p1 = r.exec("cmd /c start " + System.getProperty("user.dir") + "run.bat");