Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to redirect Lynux "system" call output to app

How to redirect Lynux "system" call output to app

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 267 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    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
    
    JonBJ 1 Reply Last reply
    1
    • Christian EhrlicherC Christian Ehrlicher referenced this topic on
    • A Anonymous_Banned275

      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
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @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 of system() with QProcess.

      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 using QProcess::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. So

      QP->startCommand("echo q  | sudo -S hcitool info 98:D3:31:F8:39:33" } );
      

      might work. But the first case with sh -c definitely works.

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved