Page 1 of 2
SLEEP 1000ms
Posted: 17 May 2011 19:39
by Ed Dyreen
If I want to pause the script for 1000ms I call a vbscript with only one command in it
Sleep.VBS
Code: Select all
Wscript.Sleep WScript.Arguments(0)*1000
I was wondering if i could do this without writing a vbscript, something like
Code: Select all
CMD.EXE wscript //nologo Wscript.Sleep 1*1000
I don't wan't to use the ping command.
Re: SLEEP 1000ms
Posted: 17 May 2011 21:17
by dbenham
Try this instead
I'm not sure which version of Windows introduced TIMEOUT, but it is built to do exactly what you are looking for.
Dave Benham
Re: SLEEP 1000ms
Posted: 18 May 2011 01:00
by orange_batch
I wonder if you borrowed that from me

nvm probably not
The answer is, sort of. Write the vbscript to a temp file, then it's all contained in your batch.
Code: Select all
set file="%temp%\sleep%random%%random%.vbs"
echo:Wscript.Sleep WScript.Arguments^(0^)*1000>%file%
cscript %file% //nologo 3
:: optional end of script
del %file%
sleep%random%%random% just helps to give the file a unique name. Of course if you want to be sure, you can always program an "if exist" loop and have it keep trying different names.
Re: SLEEP 1000ms
Posted: 18 May 2011 07:16
by Ed Dyreen
@dbenham
That's a windows7 command I believe cause XP doesn't recognize it as a valid command.
@orange_batch
You're solution uses a file, that is exactly what I want to avoid
I am gonna play a little with it, maybe something like
Code: Select all
start "Sleep" /low /wait "%comspec%" /k "cscript.exe" "//nologo Wscript.Sleep @time*1000 "
Re: SLEEP 1000ms
Posted: 18 May 2011 09:15
by Ed Dyreen
I am giving up, I think it's not possible. But why?
Code: Select all
cscript <wscript.sleep 1
ERROR: no such file
echo.wscript.sleep 1 |cscript
ERROR: no such file
I wonder where the command actiually gets lost? It is definetly send, but not accepted by cscript. Object related? send, send , send...
The only way this can be done is send ( "wscript.sleep 100" ).
That is more work than using a temp file cscript "sleep.VBS"
How ironic, gotta stop smoking that weed

Most users live on the other side of the planet i guess..
I never get a response in our timezone.
They are asleep

aDutchman
Re: SLEEP 1000ms
Posted: 18 May 2011 12:09
by jeb
Hi Ed,
Ed Dyreen wrote:Most users live on the other side of the planet i guess..
I never get a response in our timezone.
I'm in your timezone

, and many others here too ...
And yes, you can use scripts without temporary files, using the hybrid technic.
Code: Select all
@if (@X)==(@Y) @goto :Dummy @end/* Batch part
@echo off
cscript //nologo //e:jscript "%~f0"
goto :eof
Jscript part begins here */
WSH.Sleep(2000);
jeb
Re: SLEEP 1000ms
Posted: 18 May 2011 12:34
by Ed Dyreen
why ''@goto

ummy @end' there is no Dummy

Code: Select all
@if (@X)==(@Y) @goto :Dummy @end/* Batch part
Don't understand the algorithm

How can X ever be Y?
and why does it jump to a nonexistend label?
and can I use it with SetLocal EnableExtensions EnableDelayedExpansion?
Re: SLEEP 1000ms
Posted: 18 May 2011 12:56
by aGerman
Haha, exactly... it's a trick. The script code is parsed by cmd.exe and (later) by cscript.exe. That means you have to start the script with a line which is valid for both languages - Batch and JScript. The reason why you need this senseless line is to mask the /* which preludes a comment block in JScript...
Other lines are possible as well, like
@set @junk=0 /*
Regards
aGerman
Re: SLEEP 1000ms
Posted: 18 May 2011 13:04
by Ed Dyreen
Re: SLEEP 1000ms
Posted: 18 May 2011 13:18
by Ed Dyreen
It seems that it can only be done once in each batch file and not be nested
Code: Select all
@set @junk=0 /*
:Sleep ()
::(
::DOS COMMANDS ONLY
cscript //nologo //e:jscript "%~f0"
::
goto :eof ()
::)
::JS COMMANDS ONLY; FORCED END OF DOS COMMANDS WOULD BREAK JS
/*
WSH.Sleep(2000);
Re: SLEEP 1000ms
Posted: 18 May 2011 13:22
by aGerman
Makes no sense, but it's possible.
Code: Select all
@if (@X)==(@Y) @goto :Dummy @end/* 1st Batch part
@echo off &setlocal
cscript //nologo //e:jscript "%~f0"
goto FF
Jscript part */
WSH.Sleep(2000);
/* 2nd Batch part
:FF
echo "sleep" done
pause
goto :eof
*/
Regards
aGerman
Re: SLEEP 1000ms
Posted: 18 May 2011 13:22
by jeb
@aGerman: You are some seconds to fast for me
Ed Dyreen wrote:It seems that it can't be nested
Yes we can
Code: Select all
@if (@X)==(@Y) @goto :Dummy @end/* Batch part
@echo off
echo waiting...
call :sleep
echo ready
call :anotherFunc
goto :eof
:sleep
cscript //nologo //e:jscript "%~f0"
goto :eof
Jscript part begins here */
WSH.Sleep(2000);
/*
:anotherFunc
echo %0
goto :eof
rem */
jeb
Re: SLEEP 1000ms
Posted: 18 May 2011 13:26
by Ed Dyreen
And I thought I was good at it

Gotta write that shit down
Re: SLEEP 1000ms
Posted: 18 May 2011 14:15
by nitt
Ed Dyreen wrote:I don't wan't to use the ping command.
That's just... I mean, why the heck not?
Code: Select all
@echo off
set /p wait=How long do you want this to wait:
ping 0 -n %wait% > nul
echo Done!
What is wrong with that? It pauses for exactly how long you want it to, and it's better than TIMEOUT because it's universal. I always use this even though I have Windows 7, because for codes I distribute, I cannot use TIMEOUT.
Re: SLEEP 1000ms
Posted: 18 May 2011 14:59
by Ed Dyreen
I have had errors on some pc's that did not have a NIC Intel I80386sx 4MB 33Mhz 1982
XP Service pack 0 Service pack 1 was a bit of a problem..
NTLDR remember ? something. It is too long ago
Anyways the purpose is to run nomatter, it is an Unattended script for XP I have a lot of pc-clients.