B4J Question Call a shell command in interactive mode

Alessandra Pellegri

Active Member
Licensed User
I would like to open something like bluetoothctl and interact with it.
For example:
B4X:
[bluetoothctl] menu gatt
[bluetoothctl] register-service 0xFFFF # (Choose yes when asked if primary service)
[NEW] Primary Service
        /org/bluez/app/service0x10e51e0
        0xFFFF
        Unknown
[/org/bluez/app/service0x10e51e0] Primary (yes/no): yes
[bluetoothctl] register-characteristic 0xAAAA read       # (Select a value of 1 when prompted)
[NEW] Characteristic
        /org/bluez/app/service0x10e51e0/chrc0x10e5688
        0xAAAA
        Unknown
[/org/bluez/app/service0x10e51e0/chrc0x10e5688] Enter value: 1
[bluetoothctl] register-application # (This commits the services/characteristics and registers the profile)
[bluetoothctl] back
[bluetoothctl] advertise on
So I'd need to generate an event everytime the shell writes something.

Is it possible ?

Thank you
 

Erel

Administrator
Staff member
Licensed User
Not so simple but it is possible. You can start the process with InputStreamEnabled set to True and run it with RunWithOutputEvents. This will allow you to read the process output and write to the process input.

Note that the output events are raised on background threads.
 
Top