1.

Solve : Sleep command in Vista?

Answer»

Hi

I am using the code below to perform a 'sleep' in batch files using vista. It is saved as 'sleep.bat' in the System32 FOLDER:

choice /c 1 /d 1 /t 5 > nul

As it is this would sleep for 5 seconds, but I really need a way to make it variable by being able to run it as 'sleep 2', 'sleep 3' or whatever is required by just changing a number after it in another batch command.

When I had XP the Windows 2003 Resource Kit took care of this. I don't want to have more than ONE sleep file in the System32 folder, have a set of sleep files with different names and associated times or be running other batches or code to set and replace etc. if I can avoid it.

Does ANYONE have any ideas? Any help appreciated.


Thanks
some time ago, i think, macdad- did that:
here is code:

Code: [Select]@echo off
setlocal enableextensions

:SETUP
set sec=0
set /a sec=%1
set cout=0

:LOOP
set time_1=%time:~-4,1%
:ADD
set time_2=%time:~-4,1%
if not %time_1%==%time_2% (GOTO COUNT)
goto ADD

:COUNT
set /a cout+=1
if %cout% equ %sec% (goto :EOF)
goto LOOP

a little bit edited by me i think (i dont remember )

EDIT:

save this as sleep.bat and put to C:\windows\system32\
and you can use it by ex. Code: [Select]sleep 3
EDIT2:

if you dont want to put this to system32 just include this bat to you script and call it Does exactly what I need... Thanks devcom.
What's wrong with this?

Code: [Select]choice /c 1 /d 1 /t %1 > nulNothing. Yes this also works. Thanks.

As you might deduce from my handle my base is with MS Access. I can obviously see what difference the % makes, and get the idea of what devcoms code is doing (In the end I'm just happy it works), but if you could let me KNOW what the % does actually represent that would be useful for me.

Thanks both for your help...

%1 through %9 are command line arguments.


For example, if somebody invoked your batch like this:

Code: [Select]batch filename.txt /d /e

then %1 would be filename.txt, %2 would be /d, and %3 would be /e.

obviously these are different if you specify something else on the commandline.OK, I see. Thanks a lot for all the replies. Quote from: BC_Programmer on April 09, 2009, 06:04:38 PM

%1 through %9 are command line arguments.


For example, if somebody invoked your batch like this:

Code: [Select]batch filename.txt /d /e

then %1 would be filename.txt, %2 would be /d, and %3 would be /e.

obviously these are different if you specify something else on the commandline.

I want to make my own sleep command, but my code doesn't work.

Code: [Select]@echo off
if not "%2"=="/m" ping localhost -n %1 -w 1000 > nul & exit
ping localhost -n %1 -w %3 > nulI want it so if they type sleep 2 it will sleep for 2 seconds, but if they type sleep 2 /m 1500 It would sleep for 2*1500 miliseconds.

It just seems to ignore the /m and only runs the first part...why don't you enter echo commands that echo what %1 through %9 are?

EDIT:


just remembered something:


instead of "hard-coding" where the parameter is, use environment variables to store the various settings before you start executing.

you can use the SHIFT command- for example:


Code: [Select]
REM INIT the vars to 0...
SET MSWITCH=0
SET FNAME=

:START
SET GOTSWITCH=0
if %1!==! goto CONTINUE

REM TEST %1 here, for switches, filenames, etc.

if "%1"=="/m" SET MSWITCH=1 & SET GOTSWITCH=1
if "%1"=="/M" SET MSWITCH=1 & SET GOTSWITCH=1



if %GOTSWITCH%=0 set MCOUNT=%1

shift
GOTO START:

CONTINUE:

if %GOTSWITCH%=1 echo /m switch specified.
if %GOTSWITCH%=0 echo /m switch not specified.

echo count specified was %MCOUNT%

Quote from: BC_Programmer on April 10, 2009, 06:06:29 PM
why don't you enter echo commands that echo what %1 through %9 are?

EDIT:


just remembered something:


instead of "hard-coding" where the parameter is, use environment variables to store the various settings before you start executing.

you can use the SHIFT command- for example:


Code: [Select]
REM INIT the vars to 0...
SET MSWITCH=0
SET FNAME=

:START
SET GOTSWITCH=0
if %1!==! goto CONTINUE

REM TEST %1 here, for switches, filenames, etc.

if "%1"=="/m" SET MSWITCH=1 & SET GOTSWITCH=1
if "%1"=="/M" SET MSWITCH=1 & SET GOTSWITCH=1



if %GOTSWITCH%=0 set MCOUNT=%1

shift
GOTO START:

CONTINUE:

if %GOTSWITCH%=1 echo /m switch specified.
if %GOTSWITCH%=0 echo /m switch not specified.

echo count specified was %MCOUNT%

What???Quote

you can use the SHIFT command- for example:

That was the concept I was trying to get across.


Discussion

No Comment Found