Question: I want to execute a `.bat` file from a Java program.

I declared the command for the `.bat` like:

`"cmd.exe", "/C", "Start", "C:\\File\\batfile.bat"`

I use Windows XP and Eclipse Helios.

### Code

```
String cmd;
        try {
            String[] command = { "cmd.exe", "/C", "Start", "C:\\File\\batfile.bat" };
                Runtime r = Runtime.getRuntime();
                Process p = r.exec(command);
                p.waitFor();

                } catch (Exception e) 
                {

                System.out.println("Execution error");} 

```

Why is it looking for my `.bat` file in the **project directory** of Eclipse?

Answer: 
The process cmd.exe (picked from your PATH environment variable) is created with the current working directory the same as in the parent process (eclipse.exe = java). That is most likely c:\eclipse or the workspace dir.

If it cant find the file (C:\File\batfile.bat) it tries the current working dir. If you run this code using Run As Java try to change the working directory there. Also make sure the BAT file does exist.
To ensure the execution of a specific file, provide the **complete path** instead of just the executable name (which will only run from context of where the JVM was started - possibly unexpected within some IDE):

```
try{
     Runtime.getRuntime().exec(".bat file complete path");
    } catch(IOException e) {
         System.out.println("exception");
    }

```