Waiting Dos Command?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Waiting Dos Command?

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Posts
    4

    Waiting Dos Command?

    Hi;

    In one of our projects, we have to call a dos command in java. That seems ok however there is a problem about code. It gives an exception because the remaning program goes without waiting the dos command's completion.

    Code:
    Runtime r = Runtime.getRuntime(); 
    r.exec("cmd /C sort 1.txt /O 2.txt");
    Above code, makes a sort in 1.txt and saves it to 2.txt.. My code goes without waiting the 2.txt to be created and gives an exception like couldn't found 2.txt . Thanks for any help, i hope i could explained clearly what i wanted to ask..

  2. #2
    Join Date
    Sep 2005
    Location
    istanbul / Turkey
    Posts
    133

  3. #3
    Join Date
    Nov 2005
    Posts
    4
    Thanks for link however as it seems, petter from codeguru forums found an efficient solution. I'm posting it here for if someone needs it...


    Quote Originally Posted by wildfrog
    To wait until the 'child process' has completed, you can do something like this:
    Code:
    Runtime r = Runtime.getRuntime(); 
    Process p = r.exec("cmd /C sort 1.txt /O 2.txt");
    
    // wait for it to complete
    try
    {
        p.waitFor();
    } catch (InterruptedException e)
    {
        // wait was interrupted
    }
    - petter

Similar Threads

  1. waiting for shell command to complete
    By kgkidd in forum VB Classic
    Replies: 1
    Last Post: 09-20-2005, 01:40 PM
  2. using "runas" dos command from a webapp
    By Jeremiah in forum .NET
    Replies: 0
    Last Post: 10-22-2002, 10:36 AM
  3. run dos command from html page
    By steve hamilton in forum Web
    Replies: 3
    Last Post: 05-20-2002, 07:00 PM
  4. access denied - dos command from an asp
    By jp in forum Security
    Replies: 2
    Last Post: 02-01-2001, 04:41 AM

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


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center