Solved

pausing a DOS application

Posted on 2007-03-26
12
2,880 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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 24

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 24

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 24

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 24

Expert Comment

by:Mohammed Hamada
ID: 18807341
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

730 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