In the Linux prompt, I can run
sleep 5 && echo hello & to delay a command to get executed after 5 seconds but how can I do this in Windows 7s' command prompt?
To explain further what I'm trying to do: In the end I need to execute a python script, such as the one below but in Windows 7. The python script needs to finish and exit. Then after a while I want the Windows machine to execute the command.
command = 'sleep 5 && echo hello'
p = subprocess.Popen(command, shell=True)
There is no direct solution for delay on windows prompt. One solution i've used was as follow:
Create wait.bat file
@ping 127.0.0.1 -n %1% -w 1000 > nul
and while calling command from python use it like:
import subprocess command = 'wait.bat 5 & echo hello' p = subprocess.Popen(command, shell=True)
On Windows, you get the
sleep command (e.g.:
sleep 3 for 3 seconds pause). However, this command may not be installed.
An alternative is (on Windows):
ping -n 3 127.0.0.1 >nul
To do this from the Windows cmd shell you can just ping an invalid ip address wit ha no of ms e.g.
ping 18.104.22.168 -n 1 -w 1000 > nul
to wait one second.
Or to do this in Python you can import sleep from the Time library e.g.
from time import sleep sleep(1)
You just put the no of seconds as the arguement.