[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

pausing a DOS application

Posted on 2007-03-26
12
Medium Priority
?
2,894 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 5

Expert Comment

by:Fridolin Mansmann
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 5

Expert Comment

by:Fridolin Mansmann
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 250 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

650 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