Error: Caused by: CreateProcess error = 2, the system cannot find the file specified. Applies to all executable files

My goal is to run SVN commands from java for one of my requirements as I have already installed the TortoiseSVN command line tool. Added the appropriate path "C: / Program Files" / TortoiseSVN / bin "to the environment variable" Path ".

With the above setup, I can run my svn commands from the windows command line using "svn -version" and it works fine.

Now going back to code to accomplish the same thing, I am using processbuilder to do this. However, I end up getting the above error - The program "svn -version" cannot be run: CreateProcess error = 2, the system cannot find the file specified.

I have already tried the following things,

  • Using ProcessBuilder.environment checks the Path and PATH values. The path is required, but the PATH has all the required paths for applications, including the "TortoiseSVN / bin" path. So the theory cleanup ProcessBuilder has no executable location in its path.

  • At runtime, instead of just svn -version, I tried to give the full path, ie "C: / Program Files / TortoiseSVN / bin / svn.exe". This gave the same error too.

  • I tried the same code for another executable like "java -version", which also failed with the same exception.

I now have a feeling that something very basic is not right. But I've been trying to ponder this for over a day now, but I don't have any clues.

Ok one more thing, I am running this on a windows 7 box.

Below is the code I am using,


    public class RunningExecutable {

public static void main(String[] args){
    String command = "svn --version";

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {           
        ProcessBuilder svnProcessBuilder = new ProcessBuilder(command);
        String PATH = svnProcessBuilder.environment().get("PATH");
        System.out.println("PATH - " + PATH);

        String path = svnProcessBuilder.environment().get("Path");
        System.out.println("Path - " + path);

        Process procObject = svnProcessBuilder.start();

        BufferedReader cmdStreamReader = new BufferedReader(new InputStreamReader(procObject.getInputStream()));
        String cmdOutput;
        while ((cmdOutput = cmdStreamReader.readLine()) != null) {
            outputStream.write((cmdOutput + "\n").getBytes());
        System.out.println("O/p - " + outputStream.toString());
    } catch (IOException e) {
    } catch (Throwable th) {


Looking forward to any hints / pointers.

Thanks, Vicky


source to share

2 answers

This is because you are not using it ProcessBuilder

correctly. The Javadocs are pretty simple.

You cannot pass the argument --version

as part of the process name you are trying to call; it is not the file name of the process. Behind the scenes, you execute the process directly - there is no shell involved.

ProcessBuilder svnProcessBuilder = new ProcessBuilder("svn", "--version");




You need to separate the executable from its arguments:

new ProcessBuilder("svn", "--version")


For more examples and examples, see the ProcessBuilder JavaDoc constructor .



All Articles