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.


>> REGISTER NOW TO START POSTING


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

Results 1 to 2 of 2

Thread: Passings arguments to a batch file while executing from Java.

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Passings arguments to a batch file while executing from Java.

    Hi,

    I want to pass a argument to a batch file using Runtime.exec() method.
    I am using below code to execute batch file:
    Runtime r = Runtime.getRuntime();
    Process proc = null;
    proc = r.exec("create.bat", null, new File("C:\\apache-james-3.0-beta4\\bin"));

    I placed "create.bat" under "C:\\apache-james-3.0-beta4\\bin".

    In "create.bat" I have:
    james-cli -h localhost -p 9999 adduser %1 Welcome123!

    Please help me to pass argument using above.

    Thanks,
    Shareef


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

    Default Re: Passings arguments to a batch file while executing from Java.

    What happens when the code is executed? Add code to read and display the streams returned by the Process returned by the exec() method so you see any messages.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Executing a file
    By usama8800 in forum Java Theory & Questions
    Replies: 5
    Last Post: February 22nd, 2013, 03:00 PM
  2. Error codes trying to run a batch file
    By any-mgzt in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 3rd, 2013, 07:18 AM
  3. Run a jar file inside a batch file with Windows 7 Task schduler
    By kingnachi in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 15th, 2012, 09:20 AM
  4. Generating a Batch File - Static Method Error
    By Stroypet in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 17th, 2012, 11:42 AM
  5. calling a java a class connected to derby from a batch file
    By Reem in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 31st, 2010, 03:01 PM