Hostapd_cli in interactive mode ,how to get result that comes with delay

I have 2APs in one domain (802.11r\kv on)
hostapd.cli has a timer for polling every 300 seconds to check if STA is still there.
if the STA wont anwer for an emty frame it got disconnected.
I need to do it myself (in my script)
If i use a command like this

root@kikas_1:~# hostapd_cli -p /var/run/hostapd -i wlan0 poll_sta EE:52:2A:09:59:BA

It seems like this command only sends emty frame but in responce there is OK is the STA is still attached to AP but can be not in range and stll it will say OK

but if i go to hostapd_cli console i can see responce like

<3>AP-STA-POLL-OK ee:52:2a:09:59:ba

So how do i catch this responce using bash/ash ?
If i use command

the aswer is always OK no matter if STA is not in range
so answer comes to hostapd_cli console

managed to catch it llike this

result=$(echo "poll_sta EE:52:2A:09:59:BA" |hostapd_cli |grep 'ee:52:2a:09:59:ba')
echo $result

in hostad console answer is always <3>AP-STA-POLL-OK ee:52:2a:09:59:ba
but via command sometime the aswer is empty though the STA is in range , maybe i need to add some delay for answer but how

in log file always correct answer
in interactive mode always correct
but using the command

echo "poll_sta EE:52:2A:09:59:BA" |hostapd_cli |grep 'ee:52:2a:09:59:ba'

50-80% wrong answers
somhow there suposed to be a pause if a a STA didnt aswer instantly the result is empty

This seems rather closely related to your previous topic:

Is there a reason you need this in a unique thread?

You can reduce hostapd poll interval to achieve your scheduling automatically.

i need instant check if STA went to other AP within 2 seconds
and i can dissociate the STA

That topic was about why there is always OK in responce but as i figured out the answer OK means the STA is on AP and frame to check was send sucseffully
answer from the STA goes to hostapd and can be catched there

You can find STA associating somewhere else in mesh using centralizing syslog

Syslog can be overfull with other messages |grepping from log will take time,
best to catch it directly from hostapd

Sorry, that is the only way, force polling can just make assumption based on perceived disconnection that client connected somewhere else.

poll_sta via hostapd_cli command wont disconect a STA , it sends a fame only and
responce comes to hostapd_cli console.
so there is no way to wright a script wich will connect to hostapd_cli send a command then wait 2 second and grep the answer ?
In interactive mode all works correctly and i need this
my script send offer to relocate to other AP if lvl less than -65 for 3 seconds after that i need to check if the STA went from curent AP and if it went and appered on other i cant send dissaciate

Nobody else will write that for you. You can pipe log from logread -f and send commands in background. THAT WILL NOT TELL YOU WHETHER CLIENT IS AT OTHER AP.

other AP will send nothication to current AP via ssh if the STA mac just connected ,but for now i just want to get this working correctly.
In interactive mode all works perfect
i dont really need to write whole scripte,i need just a tip

You are trying to reduce inactivity poll to 2 seconds and reinventing log analysis pairing 2 related records since forever.

all i wanted is to send polling frame ,wait for answer of that frame and determinate that station is not in range .or in it.
Piping logread or hostapd output imposible to be sure if the polling-ok is related to last frame or previus one ,cause STA can move from one to another every 4 seconds , so there can be polling-ok from previus check . And i cant tail last line there can be other events.

That is the only function of idle polling by hostapd.
Once 540ms becomes 300000ms AP will poll sta if it is still alive. Modern systems will not stay silent for that long....

iwinfo phy1-ap0 assoclist
--:--:--:--:--:93  -54 dBm / -90 dBm (SNR 36)  540 ms ago
        RX: 6.0 MBit/s                                 93056 Pkts.
        TX: 433.3 MBit/s, VHT-MCS 9, 80MHz, VHT-NSS 1    158586 Pkts.
        expected throughput: unknown

yes hostapd does it ,

poll_sta ee:52:2a:09:59:ba
if[ no responce ] then
disassociate ee:52:2a:09:59:ba
echo "POLL-OK">>/log

that is what hostapd does by itself
And i need do the same when i wanted maybe wont even disassociate but to check
In interactive mode works 100% and it would work via command but i noticed in interactive mode that sometimes a STA sends answer like 0.5 seconds late , like a lagg, so in command mode it wont wait if a STA responce instantly i get correct info if it lags i get not correct info

You want to push back hostapd timer, make it short and all is done ok