How to redirect Lynux "system" call output to app
-
I am getting little " gun shy" to ask questions...
please JUST ignore my post if I asked this one, two or three years before....I need to output "system" call to both console and my app - for user info / processing.
I want to learn more about "std" hence I am NOT interested in other options, likers QProcess etc.
int RESULT = system(" echo q | sudo -S hcitool info 98:D3:31:F8:39:33 ") ;
This is for TEST "generating error " only
QProcess *QP = new QProcess(); QP->start(" echo q | sudo -S hcitool info 98:D3:31:F8:39:33 ") ;
Here is current console output - both "progress" and "error".
I need to put both to app.Here is a "good " output
Requesting information ... Can't create connection: Operation not permitted "\u0000" "void MainWindow_Bluewtoothctl_Dialog::on_pushButton_19_clicked() @ line 6727" " echo q | sudo -S hcitool info 98:D3:31:F8:39:33 " "void MainWindow_Bluewtoothctl_Dialog::on_pushButton_19_clicked() @ line 6743" [sudo] password for nov25-1: Requesting information ... BD Address: 98:D3:31:F8:39:33 OUI Company: Shenzhen Bolutek Technology Co.,Ltd. (98-D3-31) Device Name: SPP-CA LMP Version: 2.1 (0x4) LMP Subversion: 0x1060 Manufacturer: Cambridge Silicon Radio (10) Features page 0: 0xbf 0xc6 0x8d 0x78 0x18 0x1e 0x79 0x83 <3-slot packets> <5-slot packets> <encryption> <slot offset>
Here with error message
Requesting information ... Can't create connection: Operation not permitted
-
C Christian Ehrlicher referenced this topic on
-
I am getting little " gun shy" to ask questions...
please JUST ignore my post if I asked this one, two or three years before....I need to output "system" call to both console and my app - for user info / processing.
I want to learn more about "std" hence I am NOT interested in other options, likers QProcess etc.
int RESULT = system(" echo q | sudo -S hcitool info 98:D3:31:F8:39:33 ") ;
This is for TEST "generating error " only
QProcess *QP = new QProcess(); QP->start(" echo q | sudo -S hcitool info 98:D3:31:F8:39:33 ") ;
Here is current console output - both "progress" and "error".
I need to put both to app.Here is a "good " output
Requesting information ... Can't create connection: Operation not permitted "\u0000" "void MainWindow_Bluewtoothctl_Dialog::on_pushButton_19_clicked() @ line 6727" " echo q | sudo -S hcitool info 98:D3:31:F8:39:33 " "void MainWindow_Bluewtoothctl_Dialog::on_pushButton_19_clicked() @ line 6743" [sudo] password for nov25-1: Requesting information ... BD Address: 98:D3:31:F8:39:33 OUI Company: Shenzhen Bolutek Technology Co.,Ltd. (98-D3-31) Device Name: SPP-CA LMP Version: 2.1 (0x4) LMP Subversion: 0x1060 Manufacturer: Cambridge Silicon Radio (10) Features page 0: 0xbf 0xc6 0x8d 0x78 0x18 0x1e 0x79 0x83 <3-slot packets> <5-slot packets> <encryption> <slot offset>
Here with error message
Requesting information ... Can't create connection: Operation not permitted
@AnneRanch
In this post you say " NOT interested in other options, likers QProcess". In your other post at https://forum.qt.io/topic/154638/help-to-analyze-convert-command-string you say "I need to use QProcess defined as". Let's assume you do want to know how to do equivalent ofsystem()
withQProcess
.system()
takes a string, like you would type into a shell/command prompt, and passes it to a shell to execute. It uses/bin/sh
as the shell. And that accepts/bin/sh -c "command_line_here"
So the direct equivalent for your command usingQProcess::start()
is:QP->start("/bin/sh", { "-c", "echo q | sudo -S hcitool info 98:D3:31:F8:39:33" } );
Note that whatever your desired command line is it must be passed as a single argument after the
-c
first argument.I don't have Qt6, you may do. There you might find that the newly introduced
startCommand()
method does the shell for you, I don't know. SoQP->startCommand("echo q | sudo -S hcitool info 98:D3:31:F8:39:33" } );
might work. But the first case with
sh -c
definitely works.