• Rob's side project: I recently started Gun-Forums.com and we currently have a $100 raffle - if you're into guns, join up and enter the raffle to win $100.00. Gun Forums

Making "system" calls from within C++ code


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

[email protected]:~$ 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"

[email protected]:~$ bluetoothctl
Agent registered C++ process is topped

Any help will be appreciated

Members online