Solved

pausing a DOS application

Posted on 2007-03-26
12
2,881 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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
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

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

An article on effective troubleshooting
This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

726 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