This page was exported from phaq [ http://phaq.phunsites.net ] Export date:Fri Apr 26 14:39:35 2024 / +0000 GMT ___________________________________________________ Title: No "sleep" command for batch files? Make it a choice! --------------------------------------------------- I just trapped myself while hacking up a batch file. Used to shell scripting I wanted to add a delay to the batch using "sleep". Dough! Bad Idea! Bad command or filename. Smash your head here to continue {(x)}! So I winded up my memories from stoneage. Wasn't there the choice command!? Yeah, after some lurking around with the '/?' feature I had stuck it together: choice /c 1 /d 1 /t 1 > nul While "/c 1" sets the choice values (1 is my value) "/d 1" sets the default choice value (which is 1 from above) "/t 1" sets the timeout to 1 second (or whatever is appropriate) "> nul" means the same as ">/dev/null": send output to nirvana (notice there being only one 'l' however) Of course this may be bothersome to type if you use it often, so a "batch function" may be better, especially when you need other batch tricks to get around DOS command limitations (lazy man's approach: create a second batch file for it). @echo off rem ******************* rem check args rem ******************* :checkargs if "%1/" == "func/" goto callfunc goto main :_checkargs rem ******************* rem call functions rem ******************* :callfunc shift rem we could do "goto %1" instead rem if there is a lot of functions if "%1/" == "sleep/" goto sleep goto exit :_callfunc rem ******************* rem function sleep rem ******************* :sleep shift choice /c 1 /d 1 /t %1 > nul goto exit :_sleep rem ******************* rem main body rem ******************* :main echo hello, going to sleep now call %0 func sleep 1 echo sleep is over, good bye goto exit :_main rem ******************* rem exit handler rem ******************* :exit rem if there is anything left to do, do it now. :_exit --------------------------------------------------- Images: --------------------------------------------------- --------------------------------------------------- Post date: 2007-05-05 19:35:37 Post date GMT: 2007-05-05 18:35:37 Post modified date: 2010-12-18 17:08:57 Post modified date GMT: 2010-12-18 16:08:57 ____________________________________________________________________________________________ Export of Post and Page as text file has been powered by [ Universal Post Manager ] plugin from www.gconverters.com