Reputation: 10281
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.
import subprocess
command = 'sleep 5 && echo hello'
p = subprocess.Popen(command, shell=True)
Upvotes: 1
Views: 251
Reputation: 13088
To do this from the Windows cmd shell you can just ping an invalid ip address wit ha no of ms e.g.
ping 1.1.1.1 -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.
Upvotes: 0
Reputation: 4414
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)
Upvotes: 2
Reputation: 3603
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
Upvotes: 0