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. Writing command to Terminal in Qt

Writing command to Terminal in Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 2 Posters 2.5k 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.
  • M Offline
    M Offline
    marlenet15
    wrote on last edited by
    #1

    is it possible to write a command to Terminal in Qt without opening a the Terminal window?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      QProcess comes to mind for that kind of task

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        QProcess comes to mind for that kind of task

        M Offline
        M Offline
        marlenet15
        wrote on last edited by
        #3

        @SGaist I have been looking in forums and everytime someone uses the QProcess they use

        process->start("xterm");
        

        and this causes for the Terminal to open.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          If you take a look at QProcess's documentation, you'll see an example with gzip.

          What command do you want to run ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          M 1 Reply Last reply
          1
          • SGaistS SGaist

            If you take a look at QProcess's documentation, you'll see an example with gzip.

            What command do you want to run ?

            M Offline
            M Offline
            marlenet15
            wrote on last edited by
            #5

            @SGaist
            checking if a user in Linux has sudo privilages

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              So calling sudo -v ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              M 1 Reply Last reply
              0
              • SGaistS SGaist

                So calling sudo -v ?

                M Offline
                M Offline
                marlenet15
                wrote on last edited by
                #7

                @SGaist So on the GUI, there is going to be a username and password LineEdits and when the Ok button is clicked, I want it to run the following command without the Terminal window opening in order to check:

                $ su - username
                Password:

                if password is not correct
                if username does not exist
                if user does not have sudo privileges

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  IIRC you can't pass a password to su

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  M 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    IIRC you can't pass a password to su

                    M Offline
                    M Offline
                    marlenet15
                    wrote on last edited by
                    #9

                    @SGaist What I was thinking of doing was for Qt to write the command su -username. Waits for the Terminal to process that. Then the terminal will output that it is asking for the password and so Qt will write the password. Is that possible

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      But you don't want Terminal to show its face. So yes you can to it with QProcess but again and AFAIK su requires a real terminal to input the password. IIRC sudo would be simpler to use in that case.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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