1

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

10
  • Does it work if you use the full path to the batch file? Commented May 18, 2011 at 22:30
  • I just added the full path and it doesn't work either. Commented 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. Commented 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" Commented 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. Commented May 18, 2011 at 22:43

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.