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
-
Does it work if you use the full path to the batch file?JustinKSU– JustinKSU2011年05月18日 22:30:49 +00:00Commented May 18, 2011 at 22:30
-
I just added the full path and it doesn't work either.stumped– stumped2011年05月18日 22:32:45 +00:00Commented May 18, 2011 at 22:32
-
There's too much that we miss. please explain what doesn't work and how it doesn't work.MByD– MByD2011年05月18日 22:32:48 +00:00Commented May 18, 2011 at 22:32
-
What does happen when you run it from your java code? Are you able to run any process successfully? Try replacing the contents with something other than "svn update"Kal– Kal2011年05月18日 22:35:54 +00:00Commented May 18, 2011 at 22:35
-
I replace the bat file contents with : copy C:\a.txt C:\DirectoryB and this did not work either when i executed the Java code. Again, if i double click the batch file directly, it works.stumped– stumped2011年05月18日 22:43:04 +00:00Commented May 18, 2011 at 22:43
1 Answer 1
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.