Reputation: 163
I am running the Java code from Directory A, and there is a myBat.bat file there too. I want to use Java to execute the bat file. The contents of the myBat.bat is : svn update C:\DirectoryB\file.txt
I have already downloaded the Slik SVN Windows command line client. When i double click on the bat file, it svn updates the file correctly. But not when i run my Java code.
Process p = Runtime.getRuntime().exec("cmd /C C:\\DirectoryA\\myBat.bat");
The test fails because it cannot find the file.txt that it was expecting. In order to really test the svn update, i have deleted the svn file in DirectoryB. Double clicking the bat file repopulates file.txt. The test fails with:
The system cannot find the file specified)
at java.io.FileInputStream.open
Upvotes: 1
Views: 1436
Reputation: 13728
Try it this way, should work if your bat file is correct:
try {
Process p = Runtime.getRuntime().exec("cmd /c start c:\\DirectoryA\\myBat.bat");
} catch (IOException ex) {
...
}
The idea is that .bat files are not considered to be direct executables by the Runtime.
Upvotes: 1