Making "system" calls from within C++ code

anneranch

Active Member
Joined
Mar 16, 2019
Messages
223
Reaction score
43
Credits
2,078
I like to use “system” calls to utilize “bluetoothctl” tool in C++ code.

I have no problem with this code

system("bluetoothctl help | tee /tmp/A_test_file.txt >&2");

It works as expected , outputting “help” to a file and to stderr.
Then it returns to “normal” C++ code processing.

I understand normally “system” takes “input” - in the above case “bluetoothctl” to start child process , then it outputs to stdout and then “returns” from the child program back to main flow.

I need to write a “system” call to get this output- copied from terminal

jim@jim-desktop:~$ bluetoothctl start child process
Agent registered response from child process
[bluetooth]# stay in child process / prompt

Here is my first C++ code with incorrect result:
if (system("bluetoothctl")) // OK Only "Agent registered" then stops here
perror("Failed :");
perror("Sucess :");

Result – the “system” call does not return control back to main C++ code
(this is a copy from terminal - I cannot get the real stuff from IDE since the output is on "remote terminal"

jim@jim-desktop:~$ bluetoothctl
Agent registered C++ process is topped


Any help will be appreciated
 

Members online


Top