Solved

pausing a DOS application

Posted on 2007-03-26
12
2,878 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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
 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Our Group Policy work started with Small Business Server in 2000. Microsoft gave us an excellent OU and GPO model in subsequent SBS editions that utilized WMI filters, OU linking, and VBS scripts. These are some of experiences plus our spending a lo…
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

831 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