Using call <file.bat> results in "sleep is not recognized as an internal or external command.."

Viewed 4079

I have a script that calls other commands in a for loop:

for %%x in (%CMDS::= %) do (
  call C:\%%x %1%
  echo "%%x complete"
)

However, running this results the console spitting out :

'sleep' is not recognized as an internal or external command,
operable program or batch file.

This is because the files i loop through and run have these commands in them. Why is it that if i run these files one by one they work, but when chained using call they don't? I can sleep in my terminal outside of this script..

Regards

2 Answers

Thanks to another answer, I solved this error by replacing sleep 5 in my .bat file with:

powershell -Command "& {sleep 5}"

Works fine now. Better still, also tested Stephan's suggestion:

timeout 5

Simpler, and shows a nice message like

Waiting for 0 seconds, press a key to continue ...

Note that some Windows versions require the /t option to define the time.

timeout /t 5
Related