Solved

pausing a DOS application

Posted on 2007-03-26
12
2,876 Views
Last Modified: 2012-05-05
I am trying to create a batch file application

Is it possible to pause the program for a certain ammount of seconds?

I want the program to wait 10 seconds, or wait for a key to be pressed before it's closed
0
Comment
Question by:Oscurochu
  • 4
  • 3
  • 2
  • +2
12 Comments
 
LVL 5

Expert Comment

by:mdrichards
ID: 18797913
If you want a "press any key to continute" pause just add the line "pause" to your batch file.

If you want a 10 second delay you do something like the following:

ping 127.0.0.1 -n 10 > nul

This will quietly ping the local computer 10 times and not output anything. Unfortunately there is no "native" wait for x seconds function available.

Hope this helps
0
 
LVL 3

Expert Comment

by:TheTechGuysNYC
ID: 18797958
In a DOS app, instead of returning 0 i.e.

return 0;
}

use the following

system("PAUSE");
return 0;
  }

In this case the program will wait for a user to hit a key, and then exit.

Or by including windows.h you can even use the sleep(value in milliseconds) command.
0
 
LVL 5

Author Comment

by:Oscurochu
ID: 18797980
is the windows.h file for c++, or can batch files use it too? im using a batch file.
0
 
LVL 4

Expert Comment

by:mansmanf
ID: 18798533
You can also use "sleep.exe" from the Windows Resource Kit tools within your batch file:

Usage:  sleep      time-to-sleep-in-seconds
        sleep [-m] time-to-sleep-in-milliseconds
        sleep [-c] commited-memory ratio (1%-100%)
0
 
LVL 3

Expert Comment

by:TheTechGuysNYC
ID: 18799994
mansmanf: your comment on sleep is the same as mine except for committed memory, which doesn't really pertain to his question (which is of time, not memory).

In a batch file, I believe you must execute the DOS' PAUSE command which tells the computer to wait for a key to be pressed i.e. "Press any key to continue..." will appear.
0
 
LVL 4

Expert Comment

by:mansmanf
ID: 18800754
Try this in a CMD, the sleep command can easily be used instead of PAUSE in a batch programm (.bat or .cmd), if no user confirmation is wanted.

ECHO ...... & sleep 5
will echo something and then wait for 5 seconds before ending the batch.
0
Shouldn't all users have the same email signature?

You wouldn't let your users design their own business cards, would you? So, why do you let them design their own email signatures? Think of the damage they could be doing to your brand reputation! Choose the easy way to manage set up and add email signatures for all users.

 
LVL 5

Author Comment

by:Oscurochu
ID: 18802583
Im not looking for just a sleep command, or a pause command.

Im looking for a command that waits for a timeout, or a button pressed.

I want my program to wait 10 seconds and close, UNLESS a key is pressed before the timeout.

i dont care how its done... a simple function, or if-then and loop statements.. however you can get it to work.
0
 
LVL 23

Expert Comment

by:Mohammed Hamada
ID: 18806369
This will do the trick for you ...


A common way to insert a fixed-time delay of 1–99 seconds is by using choice. This can be used in Windows 95/98/ME. In Windows NT/2000/XP you may need to install the choice command (if you clickWindows NT/2000/XP there's a download link at item (e) - but see the ping delay method, too, before you decide to download).

For Windows 95/98/ME, and a choice delay of, say 10 seconds, you can use:

REM | choice /c:delay /td,10>NUL

In Windows NT/2000/XP, REM works differently, so use a TYPE NUL pipe ?  instead:

TYPE NUL | choice /c:delay /td,10 >NUL

 Note  There is a  Space  before the redirection to >NUL, shown highlighted. A digit placed just before the operator > in Windows NT/2000/XP may conflict with redirection of STDOUT and STDERR (which uses the syntax 1> and 2> respectively). This second version also works in Windows 95/98/ME, so can be used for both Operating systems.

http://www.allenware.com/icsw/icswref.htm#WaitsFixed

0
 
LVL 5

Author Comment

by:Oscurochu
ID: 18806691
will that wait 10 seconds to shutdown, and if a key is pressed before that time limit, it shuts down?
0
 
LVL 23

Expert Comment

by:Mohammed Hamada
ID: 18806737
I don't think so unless you press the Ctrl + C buttonz to terminate the batch job. but i'll give that a shot by creating a file with the above trick.

brb
0
 
LVL 23

Accepted Solution

by:
Mohammed Hamada earned 125 total points
ID: 18807292
This is the link to the Choice Command in case you couldn't download it from the Provided link above.

http://www.dynawell.com/reskit/microsoft/win2000/choice.zip

I have made my self a batch file and It worked, except that if you hit anything other than the "y" or "n" key in those ten seconds, it will stop the timer and wait FOREVER for you to hit the correct key (a "y" or "n" in this case).

You Said that you want your program to wait 10 seconds and close, UNLESS a key is pressed before the timeout.
The key that should be pressed before the timeout is N, otherwise the wait will be forever as mentioned above.

You should write the command...

TYPE NUL | choice /ty,10 >NUL
0
 
LVL 23

Expert Comment

by:Mohammed Hamada
ID: 18807341
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now