DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2008
    Posts
    1

    problem with Invoking .bat from java

    Hi
    I am trying to invoke a run.bat from java but I am not getting expected result, this is the java code

    Java Code:

    public class test {
    public static void main(String args[]){
    try{
    Runtime.getRuntime().exec("cmd /c E:\\test\\run.bat");
    } catch(Exception e){
    System.out.println(e.getMessage());
    }
    }
    }
    The run bat file is

    CD E:\quotes
    ant full > e:\test.txt
    when I click on that batch file it works fine and gives 6kb test.txt file, when I invoke from java program it gives 0kb
    please any body help me...............

  2. #2
    Join Date
    Jun 2008
    Posts
    5

    RE: problem with Invoking .bat from java

    Searched the web, found an example with...
    ===
    try {
    Process p = Runtime.getRuntime().exec("test.cmd");
    p.waitFor();
    System.out.println(p.exitValue());
    }
    catch...
    ===

    Notice the "waitfor"
    Most likely your code is continuing before the the external process
    is completed?

    *

Similar Threads

  1. Replies: 3
    Last Post: 03-21-2007, 03:28 PM
  2. Replies: 2
    Last Post: 06-14-2006, 03:16 PM
  3. Java vs. .Net. A questionnaire
    By Basil in forum .NET
    Replies: 1
    Last Post: 05-13-2005, 06:46 AM
  4. Has Sun Given Up on the Desktop?
    By Lori Piquet in forum Talk to the Editors
    Replies: 114
    Last Post: 10-10-2002, 06:01 AM
  5. Replies: 0
    Last Post: 01-31-2002, 11:08 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links