Quantcast

Maximum PC

It is currently Fri Oct 24, 2014 5:13 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Countdown Timer in Dos
PostPosted: Thu Jun 04, 2009 12:20 pm 
Million Club - 2 Plus
Million Club - 2 Plus
User avatar

Joined: Sat Jun 07, 2008 9:29 am
Posts: 1105
Okay, so im making a Batch file to backup some data daily. i have the backup procedure all set and ready to go, but it always fails and i pinned it down on the fact that making a new folder on a server takes a little time. i was wondering if someone could give me a hand with making a countdown timer that counts to 5 seconds then runs the rest of the program.

Thanks everyone!


Top
  Profile  
 
 Post subject:
PostPosted: Thu Jun 04, 2009 8:03 pm 
Team Member Top 500
Team Member Top 500
User avatar

Joined: Mon Jan 08, 2007 1:41 pm
Posts: 2033
Because there is no batch file command that "sleeps" or counts down, you have to improvise a little. The simplest way to delay for 5 seconds is to run a program that takes 5 seconds to execute.

fairly simple...
Code:
#include <windows.h>

int main() {
    Sleep(5000);
    return 0;
    }


I compiled it for you, get it here:
http://dl.getdropbox.com/u/1203786/5seconds.exe

Stick the exe in the same directory as the batch file... i'm assuming you can take it from here...

Code:
@echo off
echo HELLO
5seconds.exe
echo WORLD
pause


qa9b


Top
  Profile  
 
 Post subject:
PostPosted: Fri Jun 05, 2009 6:32 am 
Million Club - 2 Plus
Million Club - 2 Plus
User avatar

Joined: Sat Jun 07, 2008 9:29 am
Posts: 1105
This works PERFECTLY! Thanks a lot!

is this

Code:
#include <windows.h>

int main() {
    Sleep(5000);
    return 0;
    }


whats in that exe?

Thanks!


Top
  Profile  
 
 Post subject:
PostPosted: Fri Jun 05, 2009 6:49 am 
Team Member Top 500
Team Member Top 500
User avatar

Joined: Mon Jan 08, 2007 1:41 pm
Posts: 2033
Yes, that snippet of c++ is what's in the executable. It calls the windows function Sleep(), which takes an argument in milliseconds. All the c++ program does is wait 5 seconds and then end. You could compile it yourself if you want (or change the delay) if you have a c++ compiler.


Top
  Profile  
 
 Post subject:
PostPosted: Fri Jun 05, 2009 7:09 am 
Team Member Top 500
Team Member Top 500
User avatar

Joined: Mon Jan 08, 2007 1:41 pm
Posts: 2033
Here's a more versatile version:

Code:
#include <windows.h>
#include <iostream>
using namespace std;

int main(int argc, char *argv[]) {
    if (argc != 2) {
       cout << "Error. This program requires a single argument in milliseconds to specify \nthe delay interval\nType \"delay.exe delay\", where \"delay\" is in milliseconds";
    }
    Sleep(atoi(argv[1]));
    return 0;
    }


DL: http://dl.getdropbox.com/u/1203786/delay.exe

This version accepts a command line argument (in milliseconds) that specifies the delay period. So if you wanted to delay for 2 seconds instead of 5, the batch file would look like this:

Code:
@echo off
echo HELLO
delay.exe 2000
echo WORLD
pause


Top
  Profile  
 
 Post subject:
PostPosted: Mon Jun 08, 2009 11:15 am 
Million Club - 2 Plus
Million Club - 2 Plus
User avatar

Joined: Sat Jun 07, 2008 9:29 am
Posts: 1105
Ahh, thats brilliant! I dont know much programming, just my DOS knoweledge, which is pretty much just limited to Windows XP's "help" in the command prompt. But that second option is definatly the way to go for me! Thanks!! Ill try it out tomorrow when i get some free time!! :D


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

© 2014 Future US, Inc. All rights reserved.