CEC batch commands fail when CEC-Tray is running

If your cec-client batch scripts appear to do nothing — even though CEC is clearly working through CEC-Tray — the cause is almost always that CEC-Tray already has exclusive use of the adapter.

Only one application can use the CEC adapter at a time. If CEC-Tray is running (including minimised to the system tray), cec-client cannot connect to the adapter and will fail silently.

Why this happens

The USB-CEC adapter can only be held by one process at a time. CEC-Tray opens a connection to the adapter when it starts and keeps it open continuously. When a batch script calls cec-client -s, it attempts to open the same adapter and fails to connect — but produces no visible error, so the script appears to run successfully while doing nothing.

This is the same reason CEC-Tray itself warns you before launching Kodi: "Starting Kodi will exit this application, as only one program can be using the adapter at a time."

Fix: close CEC-Tray before running batch commands

1
Exit CEC-Tray completely

Open CEC-Tray, then go to 
File → Close


Alternatively, right-click the CEC-Tray icon in the taskbar and choose Close window
.
Closing the window is not enough — CEC-Tray minimises to the tray and keeps the adapter open.
2
Run your batch script

With CEC-Tray closed, CEC-Client can now connect to the adapter. Your script should execute as expected.
3
Verify CEC-Client is in your PATH

If the script still fails, check that cec-client.exe is accessible. Use the full path to be certain:
"C:\Program Files\Pulse-Eight\USB-CEC Adapter\cec-client.exe" -s


so the full command paths to use when editing


Tv_on 

@echo off
echo as | "C:\Program Files\Pulse-Eight\USB-CEC Adapter\cec-client.exe" -s


Tv_off


@echo off
   echo standby 0 | "C:\Program Files\Pulse-Eight\USB-CEC Adapter\cec-client.exe" -s


Common batch command reference

The correct syntax for single-command scripts using the -s flag is to pipe the command into cec-client:

Turn TV off (standby)

@echo off echo standby 0 | cec-client -s

Turn TV on (active source)

@echo off echo as | cec-client -s
Address reference: 0 is the TV's logical CEC address. Use F for broadcast (all devices). You can confirm addresses on the CEC bus using the CEC tester tab in CEC-Tray while it is running.

Understanding standby and PC sleep

If you find your PC goes to sleep when sending a standby command to the TV, this is a separate but related behaviour. When the TV receives a standby command it sends a broadcast standby back onto the CEC bus. If CEC-Tray is configured to put the PC to sleep when it receives a standby signal, this echo from the TV will trigger it.

Target addressWhat happensPC affected?
0 — TVStandby sent to TV. TV may echo a broadcast standby back onto the bus.Possibly, via TV echo
F — BroadcastStandby sent to all devices on the CEC bus.Yes, by design
1 — Recorder (PC)Standby sent only to the PC's own logical address. No TV echo.Yes, directly

To prevent the PC sleeping when scripts send a TV standby, disable Power off on standby in the CEC-Tray Configuration tab.


Related articles

Need help getting your CEC scripts working?
Our support team can help diagnose adapter connectivity and CEC bus issues.
UK: 01202 413 610 | US: (858) 748-8250 | support@pulse-eight.com

Was this article helpful? If not, submit a support ticket and our team will help.