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: 
Remove `Start` from the command - it's unnecessary - and try:

```java
String[] command = { "cmd.exe", "/C", "C:\\File\\batfile.bat" };

```
I faced the same scenario and following helped me to execute `bat` successfully via java.

```
String[] commands = {"C:\\Windows\\System32\\cmd.exe", "/c", "bat_script_location.bat"};
Process process = Runtime.getRuntime().exec(commands, null, "output_directory_path");
process.waitFor();
int statusBatchJob = process.exitValue(); // to check the status of execution

```