Calling a Batch file from Java using the exec command.

Discussion in 'Java' started by jds, Jul 2, 2003.

  1. jds

    jds Guest

    I am trying to call a batch file from java and expect the batch file
    to be executed, but the exec command just comes back without doing
    anything. I am working on Windows2000 jdk1.3.1_03. I am truly baffled-
    has to be something elementary that I am missing here. Any input will
    be helpful.

    Thanks,

    jds.

    1. Here is the test program test.java
    ---------------------
    import java.io.*;
    class test{

    public static void main(String args[])
    {
    try
    {
    System.out.println("Running the batch script");
    Runtime.getRuntime().exec("test.bat");
    System.out.println("Finished running the batch script");
    }
    catch(Exception e) {
    System.out.println("Error creating the FileInfo panel: " +
    e);
    e.printStackTrace();
    }
    }
    }
    ---------------------

    2. Here is the result of the java run
    C:\>javac test.java
    C:\>c:\jdk1.3.1_03\bin\java.exe -classpath . test
    Running the batch script
    Finished running the batch script

    * No notepad was launched

    3. Here is test.bat
    ---------------------
    echo "testing"
    echo "testing again"
    CALL notepad
    --------------------
    3. Here is the output of test.bat
    C:\>test.bat
    C:\>echo "testing"
    "testing"
    C:\>echo "testing again"
    "testing again"
    C:\>CALL notepad
    C:\>

    * Notepad was launched.
     
    jds, Jul 2, 2003
    #1
    1. Advertising

  2. (jds), Wed, 02 Jul 2003 13:29:21 -0700:

    > I am trying to call a batch file from java and expect the batch file
    > to be executed, but the exec command just comes back without doing
    > anything. I am working on Windows2000 jdk1.3.1_03. I am truly baffled-
    > has to be something elementary that I am missing here. Any input will
    > be helpful.


    http://groups.google.nl/groups?q=batch exec java&ie=UTF-8&oe=UTF-8&hl=nl&btnG=Google zoeken

    I think you're path settings are wrong. (just see the previous posts)

    greets.
    Bhun.
     
    dhek bhun kho, Jul 2, 2003
    #2
    1. Advertising

  3. jds

    pizzapie

    Joined:
    Sep 11, 2010
    Messages:
    1
    hey you guys!! i fount an amazing new way to wait for the thread to stop by itself :)

    do this:
    Code:
    Process process = ...
    process.waitFor(); // waits for it to terminate
    
     
    pizzapie, Sep 11, 2010
    #3
  4. jds

    Nitin Yadav

    Joined:
    Oct 3, 2011
    Messages:
    2
    Hey, Please can you explain it with an example..please...please...please...:)
     
    Nitin Yadav, Oct 3, 2011
    #4
  5. jds

    Nitin Yadav

    Joined:
    Oct 3, 2011
    Messages:
    2
    Hey, Please can you explain it with an example...please...please...please...
     
    Nitin Yadav, Oct 3, 2011
    #5
    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. Chris
    Replies:
    1
    Views:
    1,568
    Chris
    Apr 7, 2004
  2. Charlie Zhang
    Replies:
    5
    Views:
    6,570
    Qu├ębec
    Jun 19, 2004
  3. Replies:
    5
    Views:
    4,098
    Knute Johnson
    Oct 18, 2006
  4. Mark C.
    Replies:
    14
    Views:
    718
    Evertjan.
    Jan 25, 2005
  5. Guillermo Riojas
    Replies:
    0
    Views:
    200
    Guillermo Riojas
    Nov 26, 2010
Loading...

Share This Page