The Sleep command in a batch file?

When I write a batch file to run automatically, how can I write it so that when I run a batch file, it can pause for a couple of seconds between commands?

Context:

psexec \\server -u user -p pass cmd [there needs to be a pause here for psexec to establish a connection] dir /s >output.txt \\server\shared 

* Note: the reason I run the dir server command using psexec rather than locally is that it is much faster to run dir on the local computer than remotely, and time is of the essence.

When I do this manually, itโ€™s obviously easy, Iโ€™m just waiting. But running a batch file forces it to run all commands at close speeds next to each other, regardless of the state of completion of the last command. How to pause?

+6
source share
4 answers

I think the information here: http://malektips.com/xp_dos_0002.html will explain this better than me.

However, there is still an error handling problem (what if the remote machine is not working?). cmd.exe is completely useless for any remote actions for the most part, using powershell would allow much more.

EDIT ::

In fact, you can execute a program stored locally with psexec (it is copied and executed locally on the server side) - would this be a more viable alternative?

Not knowing which commands you intend to use to do this much further.

EDIT (2) ::

If this is only one command that you run, just save it in a separate file, for example "remote_dir_listing.cmd", and then use psexec with

 psexec \\server -u <user> -p <pass> -c -f remote_dir_listing.cmd 

This will copy the local file to the remote side each time it is executed (if you want to expand it). Thus, you will get around the need for a pause altogether - only when psexec opens the pipes does it start, and as soon as it finishes, it quietly closes.

+2
source

On Windows Vista / Windows 7, you can use the timeout command:

 timeout /T [delay in seconds] /NOBREAK > NUL 

In previous versions of Windows, you can use the ping command (the ping command has 1000 ms of delay between each iteration):

 ping -n [delay in seconds + 1] 127.0.0.1 > NUL 

Some versions of Windows (for example, Windows Server 2003 ) have the sleep.exe executable file:

 sleep [delay in seconds] 

Note. The Windows Resource kit for 2003 contains the sleep.exe command.

If you do not know the version of Windows, just use the ping hack, as it will be available.

+24
source

On a later version of Windows, there is a timeout command:

 timeout /T 10 
+7
source

The Windows Resource Kit for Windows 2003 will be installed on Windows XP. It contains SLEEP.EXE, which can be used from a batch command file.

download here http://www.microsoft.com/download/en/details.aspx?id=17657

+3
source

Source: https://habr.com/ru/post/900462/


All Articles