excute command

Discussion in 'Java' started by mory2311, Nov 4, 2006.

  1. mory2311

    mory2311 Guest

    Hi all,

    I'm asking about how to excute DOS command via Java code ?

    can anybody guid me ?

    thank you
    mory2311, Nov 4, 2006
    #1
    1. Advertising

  2. Hello,

    > I'm asking about how to excute DOS command via Java code ?



    Start with this:
    Runtime.getRuntime().exec("/path/to/batchFile.bat");

    The thing you are executing must always resolve to the path of some
    file you are going to run.

    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html#exec(java.lang.String)

    You can use another form of exec in the same class where you send in a
    string array to encapsulate arguments to the script as different array
    positions. However, even the form above that accepts a String only can
    also include space separated arguments.

    Good luck,

    Rob
    :)
    Robert Mark Bram, Nov 5, 2006
    #2
    1. Advertising

  3. mory2311

    franco Guest

    if you are using java5 process builder is very nice too. it comes in
    handy when you want to work with standard input and error, etc.

    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ProcessBuilder.html


    // minimal invocation:
    new ProcessBuilder("myCommand", "myArg").start();



    On Nov 4, 7:43 pm, "Robert Mark Bram" <> wrote:
    > Hello,
    >
    > > I'm asking about how to excute DOS command via Java code ?Start with this:

    > Runtime.getRuntime().exec("/path/to/batchFile.bat");
    >
    > The thing you are executing must always resolve to the path of some
    > file you are going to run.
    >
    > http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html#exec(j...)
    >
    > You can use another form of exec in the same class where you send in a
    > string array to encapsulate arguments to the script as different array
    > positions. However, even the form above that accepts a String only can
    > also include space separated arguments.
    >
    > Good luck,
    >
    > Rob
    > :)
    franco, Nov 5, 2006
    #3
  4. mory2311

    Jim Korman Guest

    On 4 Nov 2006 14:06:25 -0800, "mory2311" <> wrote:

    >Hi all,
    >
    >I'm asking about how to excute DOS command via Java code ?
    >
    >can anybody guid me ?
    >
    >thank you


    Take a look at Runtime.exec()

    Jim
    Jim Korman, Nov 5, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Yoshitha

    how to excute exe

    Yoshitha, Jun 28, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    1,880
    Eliyahu Goldin
    Jun 28, 2005
  2. HS1
    Replies:
    3
    Views:
    882
    Gerbrand van Dieijen
    Nov 17, 2004
  3. HAK
    Replies:
    0
    Views:
    329
  4. news
    Replies:
    1
    Views:
    335
    Ivan Vecerina
    Nov 25, 2003
  5. Replies:
    0
    Views:
    295
Loading...

Share This Page