How to sleep in a windows batch file within a non-interactive session

batch-file

I have a batch script that is executed outside of an interactive command prompt. I want to sleep for 30 seconds between two commands in it?

I've read in some responses to similar questions that you can use timeout or choice, but these fail in a non-interactive session.

ERROR: Input redirection is not supported, exiting the process immediately.

I've read in other responses to similar questions that you can use waitfor, but this will set an error level and I rely on those in the overall script.

I've seen using a ping that will fail ping -n 1 -w 30000 192.168.not.reachable > NUL and this appears to work, but that just seems wrong and I can't rely on an single IP being not reachable on all systems I'll deploy to.

Is there another way for me to try?

Thanks.

EDITS:

This answer (How to sleep in a batch file?) definitely has related material, but doesn't address the need for a solution that works outside an interactive shell. It does mention the only alternative I have now: ping, but as I ask above, I'm looking for alternatives.

Also, thanks for the PowerShell suggestions, but that's not possible now.

Best Answer

From http://www.robvanderwoude.com/wait.php

Non-DOS Scripting

Use the SysSleep function whenever you need a time delay in Rexx scripts. SysSleep is available in OS/2's (native) RexxUtil module and in Patrick McPhee's RegUtil module for 32-bits Windows.

Use the Sleep command for time delays in KiXtart scripts.

Use WScript.Sleep, followed by the delay in milliseconds in VBScript and JScript (unfortunately, this method is not available in HTAs).

The following batch code uses a temporary VBScript file to generate an accurate delay:

@ECHO OFF
REM %1 is the number of seconds for the delay, as specified on the command line
> "%Temp%.\sleep.vbs" ECHO WScript.Sleep %~1 * 1000
>> CSCRIPT //NoLogo "%Temp%.\sleep.vbs"
>> DEL "%Temp%.\sleep.vbs"

Not my solution, I just found it: