Waitfor (Sending/receiving signal (message)) - DOS/Command Prompt Reference
[Windows 7 or later](Windows Server 2003 or later) Facilitates the transmission and reception of signals over the network. This can be utilized for waiting in batch processing scenarios.
* In this context, ‘signal’ refers to a message-like entity used by the Waitfor program. The format of the signal is primarily specific to its usage with Waitfor.
Syntax
-- Syntax for sending signals waitfor[.exe] [/S <computer> [/U <user> [/P <password>]]] /SI <signal-name> -- Syntax for receiving signals waitfor[.exe] [/T <seconds>] <signal-name>
Options
- /S <computer>
- Specifies the computer designated as the signal destination by using either the computer name or the IP address (a name usable in UNC paths).
- If this parameter is omitted, the signal will be broadcast to computers in the same primary domain.
- * You cannot specify ‘
.
’ (<computer> must be a name that can access\\<computer>\IPC$
). - /U <user>
- Specifies the username for connecting to the computer. For <user>, provide either the username from the same domain or a domain-qualified username in the format ‘
<domain>\<user>
’. - /P <password>
- Specifies the password corresponding to the user specified with /U.
- /SI <signal-name>
- Specifies the name of the signal to be sent. Signal name characters can include half-width alphabets, half-width numbers, and characters in the ASCII range from 128 to 255. (For example, hyphens or slashes cannot be used.)
- Note that signals will be successfully sent (assuming the computer can be reached) regardless of whether there is a recipient waiting to receive them or not.
- /T <seconds>
- Specifies the wait time for signal reception. <seconds> will be the wait time in seconds.
- If this parameter is omitted, Waitfor will wait until the signal is received (or until an interruption like Ctrl+C occurs).
- <signal-name>
- Specifies the name of the signal to be received (waited for).
- If you specify a signal name (<signal-name>) without using ‘/SI’, it will be treated as part of the signal reception syntax.
- Note that if there is already a Waitfor waiting for a signal with the same name, you cannot specify that name.
Details
Waitfor is used to send and receive signals across processes and networks. When used in batch files or similar scenarios, it enables interactions such as ‘wait until a specific process completes’ or ‘notify when a specific process has finished’.
Internally, Waitfor uses mailslots for sending and receiving signals. The mailslot name is ‘\\<computer>\mailslot\WAITFOR.EXE\<signal-name>
’. When sending, if <computer> is not specified, it uses ‘*
’, and when waiting for signal reception, it uses ‘.
’.
* If /S is omitted, signal transmission is carried out using the name ‘\\*\mailslot\...
’. The name ‘\\.\mailslot\...
’ is not used during signal transmission. Therefore, when sending a signal to your own computer, it is necessary to specify your computer name or ‘127.0.0.1’ with the ‘/S’ option.
Samples
Sample 1
waitfor HogeSignal
Waits for a signal with the name ‘HogeSignal’. Since a timeout is not specified, it will wait indefinitely until it receives the signal or the program is forcibly terminated (Ctrl+C).
Sample 2
waitfor /S 127.0.0.1 /SI HogeSignal
Sends a signal with the name ‘HogeSignal’ to its own computer. If there is a process waiting for ‘HogeSignal’ using Waitfor in another window, that waiting process will conclude, and the execution will proceed.