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. why qprocess not execute mount command correctly ?
Forum Updated to NodeBB v4.3 + New Features

why qprocess not execute mount command correctly ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 6 Posters 655 Views 2 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.
  • Q Offline
    Q Offline
    Qt embedded developer
    wrote on 9 Jan 2023, 12:01 last edited by Qt embedded developer 1 Sept 2023, 17:24
    #1

    i have seen that when use mount /dev/sdb1 /mnt it not mount using qprocess ?

    J 1 Reply Last reply 9 Jan 2023, 15:58
    0
    • C Online
      C Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 9 Jan 2023, 15:54 last edited by
      #2

      As always when you ask questions - please clarify, re-read your question and think if someone else could really understand what you're trying to ask.

      My answer: No, noone understands your question...

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      Q 1 Reply Last reply 9 Jan 2023, 17:29
      1
      • A Offline
        A Offline
        andr
        wrote on 9 Jan 2023, 15:56 last edited by
        #3

        The 'mount <dev> <mountpoint>' version is usually run with root permissions. Do you have them?

        Q 1 Reply Last reply 9 Jan 2023, 17:21
        1
        • Q Qt embedded developer
          9 Jan 2023, 12:01

          i have seen that when use mount /dev/sdb1 /mnt it not mount using qprocess ?

          J Offline
          J Offline
          JonB
          wrote on 9 Jan 2023, 15:58 last edited by JonB 1 Sept 2023, 15:59
          #4

          @Qt-embedded-developer
          I would be surprised if that is really the case. Show your QProcess code. Check for any errors, e.g. permissions as @andr has remarked.

          1 Reply Last reply
          0
          • A andr
            9 Jan 2023, 15:56

            The 'mount <dev> <mountpoint>' version is usually run with root permissions. Do you have them?

            Q Offline
            Q Offline
            Qt embedded developer
            wrote on 9 Jan 2023, 17:21 last edited by Qt embedded developer 1 Sept 2023, 17:22
            #5

            @andr @JonB yes i have given sudo permission using sudo visudo.

            i have tested the code using system() it works fine but same thing is not working with qprocess

            1 Reply Last reply
            0
            • C Christian Ehrlicher
              9 Jan 2023, 15:54

              As always when you ask questions - please clarify, re-read your question and think if someone else could really understand what you're trying to ask.

              My answer: No, noone understands your question...

              Q Offline
              Q Offline
              Qt embedded developer
              wrote on 9 Jan 2023, 17:29 last edited by
              #6

              @Christian-Ehrlicher

              qprocess not execute below command correct way:

              sudo mount /dev/sdb1 /mnt

              what is right way to execute mount command using qprocess ?

              i know how to use qprocess. so if possible let me know what argument argument i need to pass to make it correct ?

              J 1 Reply Last reply 9 Jan 2023, 17:37
              0
              • Q Qt embedded developer
                9 Jan 2023, 17:29

                @Christian-Ehrlicher

                qprocess not execute below command correct way:

                sudo mount /dev/sdb1 /mnt

                what is right way to execute mount command using qprocess ?

                i know how to use qprocess. so if possible let me know what argument argument i need to pass to make it correct ?

                J Offline
                J Offline
                JonB
                wrote on 9 Jan 2023, 17:37 last edited by JonB 1 Sept 2023, 17:37
                #7

                @Qt-embedded-developer said in why qprocess not execute mount command correctly ?:

                i know how to use qprocess. so if possible let me know what argument argument i need to pass to make it correct ?

                Then you won't mind showing your code for this, as requested? There is not somehow something "special", or a "special argument", because of using QProcess.
                BTW this isn't going to work if your sudo requires a password.

                Q 1 Reply Last reply 9 Jan 2023, 18:00
                0
                • J JonB
                  9 Jan 2023, 17:37

                  @Qt-embedded-developer said in why qprocess not execute mount command correctly ?:

                  i know how to use qprocess. so if possible let me know what argument argument i need to pass to make it correct ?

                  Then you won't mind showing your code for this, as requested? There is not somehow something "special", or a "special argument", because of using QProcess.
                  BTW this isn't going to work if your sudo requires a password.

                  Q Offline
                  Q Offline
                  Qt embedded developer
                  wrote on 9 Jan 2023, 18:00 last edited by Qt embedded developer 1 Sept 2023, 18:02
                  #8

                  @JonB

                  QProcess OProcess;
                    QString Command,sConnectedNodePath;
                  
                    Command = "sudo mount /dev/sdb1 /mnt ";
                  
                  
                    OProcess.start(Command,QIODevice::ReadOnly);
                    OProcess.waitForFinished();
                  
                    QString sCommandOutput = OProcess.readAllStandardOutput();
                    QString StdError = OProcess.readAllStandardError();
                  
                    if(StdError.isEmpty())
                    {
                        qDebug() << "output : success";
                  
                  }
                  else{
                           qDebug() << "output : fail";
                  }
                  

                  i got success output with not mounted directory at /mnt

                  J J 2 Replies Last reply 9 Jan 2023, 19:26
                  0
                  • A Offline
                    A Offline
                    Axel Spoerl
                    Moderators
                    wrote on 9 Jan 2023, 18:38 last edited by
                    #9

                    Can you qDebug() << sCommandOutput;as well?
                    What happens if you enter the command on the command line with the user who is running the executable? Pls share the command line output as well.

                    Software Engineer
                    The Qt Company, Oslo

                    1 Reply Last reply
                    0
                    • Q Qt embedded developer
                      9 Jan 2023, 18:00

                      @JonB

                      QProcess OProcess;
                        QString Command,sConnectedNodePath;
                      
                        Command = "sudo mount /dev/sdb1 /mnt ";
                      
                      
                        OProcess.start(Command,QIODevice::ReadOnly);
                        OProcess.waitForFinished();
                      
                        QString sCommandOutput = OProcess.readAllStandardOutput();
                        QString StdError = OProcess.readAllStandardError();
                      
                        if(StdError.isEmpty())
                        {
                            qDebug() << "output : success";
                      
                      }
                      else{
                               qDebug() << "output : fail";
                      }
                      

                      i got success output with not mounted directory at /mnt

                      J Offline
                      J Offline
                      JonB
                      wrote on 9 Jan 2023, 19:26 last edited by JonB 1 Sept 2023, 19:45
                      #10

                      @Qt-embedded-developer

                        QProcess OProcess;
                        Command = "sudo mount /dev/sdb1 /mnt ";
                        OProcess.start(Command,QIODevice::ReadOnly);
                      

                      Show what overload of QProcess::start() (and what version of Qt) you think accepts a single string of sudo mount /dev/sdb1 /mnt as its first/program argument? I am not even sure which overload yours is using! Only QProcess::startCommand() accepts such a single-string command-line.

                      i got success output

                      What "success"? I see only a check as to whether StdError is empty. Which I would expect to be the case. And as @Axel-Spoerl asked, show sCommandOutput too, though I would expect that to be empty too. Plus please do confirm you have run this from the command line outside of Qt application, and its output.

                      Attach slots in yours to signals started/stateChanged/finished/errorOccurred() on your OProcess, and check return result of waitForFinished(), if you want to check its behaviour. Also exitStatus() & exitCode().

                      Also confirm whether or not your sudo requires a password anyway?

                      UPDATE
                      I see that at Qt 5.15 there was an obsoleted QProcess::start(const QString &command, QIODevice::OpenMode mode = ReadWrite), I guess that must be what you are using? You might still check the suggested slots, and show sCommandOutput too. OK, please confirm again about your sudo password as well, and we will take it from there....

                      1 Reply Last reply
                      0
                      • Q Qt embedded developer
                        9 Jan 2023, 18:00

                        @JonB

                        QProcess OProcess;
                          QString Command,sConnectedNodePath;
                        
                          Command = "sudo mount /dev/sdb1 /mnt ";
                        
                        
                          OProcess.start(Command,QIODevice::ReadOnly);
                          OProcess.waitForFinished();
                        
                          QString sCommandOutput = OProcess.readAllStandardOutput();
                          QString StdError = OProcess.readAllStandardError();
                        
                          if(StdError.isEmpty())
                          {
                              qDebug() << "output : success";
                        
                        }
                        else{
                                 qDebug() << "output : fail";
                        }
                        

                        i got success output with not mounted directory at /mnt

                        J Offline
                        J Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on 10 Jan 2023, 08:01 last edited by
                        #11

                        @Qt-embedded-developer said in why qprocess not execute mount command correctly ?:

                        Command = "sudo mount /dev/sdb1 /mnt ";

                        Please read the QProcess documentation: the parameters to the command are passed as a QStringList parameter to QProcess...

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        J 1 Reply Last reply 10 Jan 2023, 12:55
                        1
                        • J jsulm
                          10 Jan 2023, 08:01

                          @Qt-embedded-developer said in why qprocess not execute mount command correctly ?:

                          Command = "sudo mount /dev/sdb1 /mnt ";

                          Please read the QProcess documentation: the parameters to the command are passed as a QStringList parameter to QProcess...

                          J Offline
                          J Offline
                          JonB
                          wrote on 10 Jan 2023, 12:55 last edited by
                          #12

                          @jsulm
                          Like I discovered, I think OP must be using the obsoleted QProcess::start(const QString &command, QIODevice::OpenMode mode = ReadWrite). Assuming that is so, there must be a deeper reason why it fails to work, yet to be discovered from OP's future responses....

                          1 Reply Last reply
                          0

                          1/12

                          9 Jan 2023, 12:01

                          • Login

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