'Capture the event messages appearing in interactive linux command

Problem Summary: I'm running a well known program called wpa_cli which is used to interact with wpa_supplicant. More details can be found here: https://w1.fi/wpa_supplicant/devel/

wpa_cli is a command line tool which is used:

  1. To submit commands from the terminal e.g. wpa_cli -i p2p-dev-wlan0 p2p_find
  2. Interactive mode. To start interactive mode just write first part without the command at end: wpa_cli -i p2p-dev-wlan0

Once inside the interactive mode any command like p2p_find can be run as shown below:

pi@raspberrypi1:~ $ wpa_cli -i p2p-dev-wlan0
wpa_cli v2.9
Copyright (c) 2004-2019, Jouni Malinen <[email protected]> and contributors

This software may be distributed under the terms of the BSD license.
See README for more details.



Interactive mode

<3>CTRL-EVENT-SCAN-RESULTS 
> p2p_find
OK
<3>CTRL-EVENT-SCAN-STARTED 
<3>CTRL-EVENT-SCAN-STARTED 
<3>CTRL-EVENT-SCAN-STARTED 
<3>CTRL-EVENT-SCAN-STARTED 
<3>CTRL-EVENT-SCAN-STARTED 
<3>CTRL-EVENT-SCAN-STARTED 
<3>CTRL-EVENT-SCAN-STARTED 
> p2p_stop_find
OK
<3>P2P-FIND-STOPPED 

As we see here there are "event" messages from wpa_supplicant like <3>CTRL-EVENT-SCAN-STARTED that appears only in interactive mode.

Even though the full command i.e. "wpa_cli -i p2p-dev-wlan0 p2p_find" will be run in different terminal, the event messages can be seen just by starting the interactive mode in the first terminal. My question is how to capture these event messages in a file for reading them and parsing them later?

What I've tried: Unix redirection - but am not able to make it work as this is interactive mode. Unix "script" command but it is not capturing the event messages.

Please help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source