I'm developing a command line Java app that must run a program called gradlew.bat assembleRelease inside this directory: this.workDir+"/Project/CapAndroid"
So I did this:
Process p = Runtime.getRuntime().exec("gradlew.bat assembleRelease", null , new File(this.workDir+"/Project/CapAndroid"));
I am sure the file is in that directory and it works perfectly in Linux, but it did not work on Windows. I got this error:
java.io.IOException: Cannot run program "gradlew.bat" (in directory "C:\Users\Administrador\Desktop\generators\And\jobs\2247994\Project\CapAndroid"): CreateProcess error=2, The system cannot find the file specified
I think Windows has a problem to know that the command passed in the first parameter of exec() method must be executed in the directory passed in the last parameter. Linux works perfectly, also OS X too, the problem is only in Windows.
Well, i finally solved it adding cmd /c before the name of the .bat file, now it works perfectly:
Process p = Runtime.getRuntime().exec("cmd /c gradlew.bat assembleRelease", null , new File(this.workDir+"/Project/CapAndroid"));
i hope this will help someone in the future
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With