Windows 7 and later include a utility called "waitfor.exe". The program is supposed to listen and wait for a named signal to be received. It also can send a signal.
The syntax for waiting for a signal is something like: waitfor.exe somevent
The syntax for sending is supposed to be: waitfor.exe /S remotecomputer /SI somevent. There are also options for specifying a user and password to connect to a remote computer.
But I am having trouble getting this to work. The program appears to work okay when waiting for a signal. But I have never been able to get the program to work in send mode.
I've tried these possibilities:
waitfor /si someevent - produces error - ERROR: Unable to send signal 'someevent'.waitfor /s someevent - syntax errorwaitfor /s %COMPUTERNAME% someevent - syntax errorwaitfor /s %COMPUTERNAME% /si someevent - produces error - ERROR: Unable to send signal 'someevent'.I want to use this program to simply synchronize between two command windows, running as the same user. Neither is running elevated. Testing in this scenario produces the above errors.
I know I can find (or write) 3rd party utilities to do this, but I would like to use a windows built-in utility. I also would like to avoid using powershell, as its performance is poor, for my use case. Also also also, I know I can cobble together a synchronization mechanism using "if exist" on the receive side, plus creating a file on the send side (ditto for the registry, using reg.exe), but I'd like to avoid that also. The latency of such solutions is inversely proportional to performance (the receive side would need to use a polling loop).
Does anyone know how to make waitfor.exe work for this simple same-computer same-user scenario ? Or any other built-in with good performance and zero latency?
exact detail of error messages:
C:\>where waitfor
C:\Windows\System32\waitfor.exe
C:\>rem - did run "waitfor myevent" in another window
C:\>waitfor /s %COMPUTERNAME% /si myevent
ERROR: Unable to send signal 'myevent'.
C:\>waitfor /s %COMPUTERNAME% myevent
ERROR: Invalid syntax.
Type "WAITFOR /?" for usage.
C:\>
My computer is running Windows 2008 R2 server, and is part of a corporate active directory domain.
This is a simple code that implements your example:
@echo off
setlocal
if "%1" neq "" goto %1
rem Start a Send - Receive pair
start "" /B "%~F0" Send ^> pipefile.txt
call "%~F0" Receive < pipefile.txt
echo Program ending.
goto :EOF
:Send
set "line="
set /P "line=Enter a line, EXIT to end: " > CON
echo %line%
waitfor /SI dataAvailable > NUL
if /I "%line%" neq "EXIT" goto Send
echo Send part ending... > CON
exit /B
:Receive
waitfor dataAvailable > NUL
set /P "data="
echo Data received: "%data%"
if /I "%data%" neq "EXIT" goto Receive
echo Receive part ending...
exit /B
This is the output:
C:\Users\Antonio\Documents\test> test.bat
Enter a line, EXIT to end: Line one
Data received: "Line one"
Enter a line, EXIT to end: Second line sent to receive part
Data received: "Second line sent to receive part"
Enter a line, EXIT to end: exit
Data received: "exit"
Receive part ending...
Program ending.
C:\Users\Antonio\Documents\test> Send part ending...
Windows 8.1 here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With