-1

I'm trying to run multiple commands in Windows cmd. And need to sleep for ~4 seconds between the commands.

I copy my commands block to the cmd and then want them to run one after the other with breaks of 4 seconds.

My problem is that the timeout command stops the execution and not continue to the next commands:

python3 my_file.py -a
timeout /t 4 /nobreak > nul
python3 my_file.py -b
timeout /t 4 /nobreak > nul
python3 my_file.py -c

The first and the second lines are running and then it ends and shows the > sign.

(I did the same thing in Linux with the 'sleep' command ant it works perfect)

I also tried different options of the timeout command such as timeout /t 4 and timeout 4 but nothing works...

How can I do it? it must run on Windows cmd and not as batch file.

Thanks

Update:

As @JosefZ answered, my problem caused by the PASTE usage. The timeout command ignored the PASTE command, so I didn't get the next commands.

Using the PING command as his answer solved the issue.

2
  • 3
    What's your output of where python3? I suspect it's a .bat or .cmd file - then you need to call it. Commented May 30, 2024 at 14:29
  • 1
    There is no obvious syntax problem with the timeout commands you have used, although they should more correctly look like this %SystemRoot%\System32\timeout.exe /T 4 /NoBreak 1>NUL. Commented May 30, 2024 at 20:41

1 Answer 1

1

timeout /? says about the /NOBREAK parameter:

/NOBREAK Ignore key presses and wait specified time.

Ignore, i.e. choke down all content of keyboard buffer filled by a PASTE technique.

A delay can also be produced by the PING command with a loopback address (127.0.0.1), in tests this consumes less processor time than Sleep.exe or Timeout.exe. The delay between each ping is 1 second, so for a delay of 5 seconds ping 6 times.

The following code snippet should work as expected:

python3 my_file.py -a
PING -n 5 127.0.0.1 1>nul 2>&1
python3 my_file.py -b
PING -n 5 127.0.0.1 1>nul 2>&1
python3 my_file.py -c
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.