Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Replicating "terminal " command sequence

Replicating "terminal " command sequence

Scheduled Pinned Locked Moved Unsolved C++ Gurus
5 Posts 4 Posters 517 Views
  • 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 can successfully complete the following while running “terminal “.
    nov25-1@nov251-desktop:~$ sudo su
    [sudo] password for nov25-1:
    root@nov251-desktop:/home/nov25-1# ln -s -v /dev/ttyUSB0 /dev/rfcomm0

    My tasks to duplicate that sequence using C code.

    Here is my basic C code to process “command “:

         QP = new QProcess();
         QP->start("/bin/sh", QStringList() << "-c" << command);
         if(QP->Running)
          if (QP->waitForReadyRead(60000))
                 QP->waitForFinished(100);
                 ….. 
          else
             {
                 text =   " ERROR  waitForReadyRead(500) timed out ";
              }
    

    I have no issues processing test command – such as “lsusb”.

    However , here is my debug output when I use “sudo su”

    Test option ...
    BTUL->ProcessCommand_Raw elapsed time 39 mS
    sudo: a terminal is required to read the password; either use the -S option to
    read from standard input or configure an askpass helper
    sudo: a password is required

    and this is what I receive after command “sudo -S”

    Test option ...
    BTUL->ProcessCommand_Raw elapsed time 29 mS
    usage: sudo -h | -K | -k | -V
    usage: sudo -v [-ABknS] [-g group] [-h host] [-p prompt] [-u user]
    usage: sudo -l [-ABknS] [-g group] [-h host] [-p prompt] [-U user] [-u user]
    [command]
    usage: sudo [-ABbEHknPS] [-r role] [-t type] [-C num] [-D directory] [-g group]
    [-h host] [-p prompt] [-R directory] [-T timeout] [-u user]
    [VAR=value] [-i|-s] [<command>]
    usage: sudo -e [-ABknS] [-r role] [-t type] [-C num] [-D directory] [-g group]
    [-h host] [-p prompt] [-R directory] [-T timeout] [-u user] file ...

    That is telling me that “sudo -S” is invalid…

    Please note

    usage: sudo [-ABbEHknPS] [-r role] [-t type] [-C num] [-D directory] [-g group]
    [-h host] [-p prompt] [-R directory] [-T timeout] [-u user]
    [VAR=value] [-i|-s] [<command>]

    is a valid usage option – or am I missing something ?
    PS
    I would also like to find out , later - after this is resolved, why my code always “times out” when invalid command is processed.

    T JoeCFDJ 2 Replies Last reply
    0
    • A Anonymous_Banned275

      I can successfully complete the following while running “terminal “.
      nov25-1@nov251-desktop:~$ sudo su
      [sudo] password for nov25-1:
      root@nov251-desktop:/home/nov25-1# ln -s -v /dev/ttyUSB0 /dev/rfcomm0

      My tasks to duplicate that sequence using C code.

      Here is my basic C code to process “command “:

           QP = new QProcess();
           QP->start("/bin/sh", QStringList() << "-c" << command);
           if(QP->Running)
            if (QP->waitForReadyRead(60000))
                   QP->waitForFinished(100);
                   ….. 
            else
               {
                   text =   " ERROR  waitForReadyRead(500) timed out ";
                }
      

      I have no issues processing test command – such as “lsusb”.

      However , here is my debug output when I use “sudo su”

      Test option ...
      BTUL->ProcessCommand_Raw elapsed time 39 mS
      sudo: a terminal is required to read the password; either use the -S option to
      read from standard input or configure an askpass helper
      sudo: a password is required

      and this is what I receive after command “sudo -S”

      Test option ...
      BTUL->ProcessCommand_Raw elapsed time 29 mS
      usage: sudo -h | -K | -k | -V
      usage: sudo -v [-ABknS] [-g group] [-h host] [-p prompt] [-u user]
      usage: sudo -l [-ABknS] [-g group] [-h host] [-p prompt] [-U user] [-u user]
      [command]
      usage: sudo [-ABbEHknPS] [-r role] [-t type] [-C num] [-D directory] [-g group]
      [-h host] [-p prompt] [-R directory] [-T timeout] [-u user]
      [VAR=value] [-i|-s] [<command>]
      usage: sudo -e [-ABknS] [-r role] [-t type] [-C num] [-D directory] [-g group]
      [-h host] [-p prompt] [-R directory] [-T timeout] [-u user] file ...

      That is telling me that “sudo -S” is invalid…

      Please note

      usage: sudo [-ABbEHknPS] [-r role] [-t type] [-C num] [-D directory] [-g group]
      [-h host] [-p prompt] [-R directory] [-T timeout] [-u user]
      [VAR=value] [-i|-s] [<command>]

      is a valid usage option – or am I missing something ?
      PS
      I would also like to find out , later - after this is resolved, why my code always “times out” when invalid command is processed.

      T Offline
      T Offline
      Txai
      wrote on last edited by
      #2

      @AnneRanch said in Replicating "terminal " command sequence:

      That is telling me that “sudo -S” is invalid…
      Please note
      usage: sudo [-ABbEHknPS] [-r role] [-t type] [-C num] [-D directory] [-g group]
      [-h host] [-p prompt] [-R directory] [-T timeout] [-u user]
      [VAR=value] [-i|-s] [<command>]
      is a valid usage option – or am I missing something ?

      Ann, hmmm... sudo is a Unix command
      https://en.wikipedia.org/wiki/Sudo

      Folks on Unix/Linux forums are the specialists I would ask this question to

      Please visit https://unix.stackexchange.com/

      A 1 Reply Last reply
      0
      • T Txai

        @AnneRanch said in Replicating "terminal " command sequence:

        That is telling me that “sudo -S” is invalid…
        Please note
        usage: sudo [-ABbEHknPS] [-r role] [-t type] [-C num] [-D directory] [-g group]
        [-h host] [-p prompt] [-R directory] [-T timeout] [-u user]
        [VAR=value] [-i|-s] [<command>]
        is a valid usage option – or am I missing something ?

        Ann, hmmm... sudo is a Unix command
        https://en.wikipedia.org/wiki/Sudo

        Folks on Unix/Linux forums are the specialists I would ask this question to

        Please visit https://unix.stackexchange.com/

        A Offline
        A Offline
        Anonymous_Banned275
        wrote on last edited by
        #3

        @Txai Go ahead and ask...I am banned to do so there ....

        1 Reply Last reply
        0
        • A Anonymous_Banned275

          I can successfully complete the following while running “terminal “.
          nov25-1@nov251-desktop:~$ sudo su
          [sudo] password for nov25-1:
          root@nov251-desktop:/home/nov25-1# ln -s -v /dev/ttyUSB0 /dev/rfcomm0

          My tasks to duplicate that sequence using C code.

          Here is my basic C code to process “command “:

               QP = new QProcess();
               QP->start("/bin/sh", QStringList() << "-c" << command);
               if(QP->Running)
                if (QP->waitForReadyRead(60000))
                       QP->waitForFinished(100);
                       ….. 
                else
                   {
                       text =   " ERROR  waitForReadyRead(500) timed out ";
                    }
          

          I have no issues processing test command – such as “lsusb”.

          However , here is my debug output when I use “sudo su”

          Test option ...
          BTUL->ProcessCommand_Raw elapsed time 39 mS
          sudo: a terminal is required to read the password; either use the -S option to
          read from standard input or configure an askpass helper
          sudo: a password is required

          and this is what I receive after command “sudo -S”

          Test option ...
          BTUL->ProcessCommand_Raw elapsed time 29 mS
          usage: sudo -h | -K | -k | -V
          usage: sudo -v [-ABknS] [-g group] [-h host] [-p prompt] [-u user]
          usage: sudo -l [-ABknS] [-g group] [-h host] [-p prompt] [-U user] [-u user]
          [command]
          usage: sudo [-ABbEHknPS] [-r role] [-t type] [-C num] [-D directory] [-g group]
          [-h host] [-p prompt] [-R directory] [-T timeout] [-u user]
          [VAR=value] [-i|-s] [<command>]
          usage: sudo -e [-ABknS] [-r role] [-t type] [-C num] [-D directory] [-g group]
          [-h host] [-p prompt] [-R directory] [-T timeout] [-u user] file ...

          That is telling me that “sudo -S” is invalid…

          Please note

          usage: sudo [-ABbEHknPS] [-r role] [-t type] [-C num] [-D directory] [-g group]
          [-h host] [-p prompt] [-R directory] [-T timeout] [-u user]
          [VAR=value] [-i|-s] [<command>]

          is a valid usage option – or am I missing something ?
          PS
          I would also like to find out , later - after this is resolved, why my code always “times out” when invalid command is processed.

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by
          #4

          @AnneRanch said in Replicating "terminal " command sequence:

          lsusb

          You can not run sudo in qt since password is needed. It is better to do this kind of executions with (sudo + a script) before your app is launched. It is not a good design
          to run sudo inside your qt app.

          If you have to, maybe create a service which has sudo privilege. Your Qt app can send a message to the service to run these operations.

          1 Reply Last reply
          0
          • Kent-DorfmanK Offline
            Kent-DorfmanK Offline
            Kent-Dorfman
            wrote on last edited by
            #5

            @AR --

            You are going to keep having problems with these embedded command line sequences. quoting/escaping embedded command sequences is a PITA, and can be mitigated by creating subshell scripts and just calling the script instead of trying to build a long convoluted command line on execution. It also has the benefit of allowing for easier testing because you can work out the script directly and not involve Qt until you are ready.

            1 Reply Last reply
            1

            • Login

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