Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: execute bat file with arguments

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Thanked 0 Times in 0 Posts

    Default execute bat file with arguments

    Ok very simple task yet difficult for me as a novice to solve.
    I have a bat file in a folder in my c: drive. This bat file call an EXE file inside the same folder. The BAT file also feeds some other files to teh EXE to run properly. The bat file works fine if I run it through command prompt.

    I tried this code from eclipse but nothing happens i.e. Bat is not executed at all - where is the mistake?

    import java.io.*;
    import java.util.*;
    public class utilities {
    	public static void main(String[] args) throws InterruptedException {
    		//cmd = cmd+" "+a+" "+b;
    		try {
    			String[] cmd = new String[]{"cmd.exe" ,"/c","C:\\EnergyPlusV6-0-0\\RunEplus.bat", "test5", "my"};
    			//cmd  = new String[]{"cmd" ,"/c","C:\\EnergyPlusV6-0-0\\Epl-run.bat"};
    			Process p = Runtime.getRuntime().exec(cmd);
    		} catch (IOException e) {

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,708 Times in 2,658 Posts

    Default Re: execute bat file with arguments

    You should add code to look at the output and error Streams returned by the Process to see if there are any errors.

Similar Threads

  1. [SOLVED] .jar file won't execute
    By pajfilms in forum What's Wrong With My Code?
    Replies: 27
    Last Post: August 3rd, 2011, 07:43 PM
  2. Tiny problem with arguments.
    By Melawe in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 15th, 2011, 02:26 PM
  3. Could not execute the file
    By miaaa00 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 20th, 2011, 08:28 AM
  4. Code doesn't execute properly
    By fride360 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 12th, 2011, 12:36 PM
  5. command line arguments
    By rizla in forum Member Introductions
    Replies: 3
    Last Post: December 12th, 2010, 11:14 PM