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 ?
Qt 6.11 is out! See what's new in the release blog

why qprocess not execute mount command correctly ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 6 Posters 956 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.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on 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
    1
    • andrA Offline
      andrA Offline
      andr
      wrote on last edited by
      #3

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

      Q 1 Reply Last reply
      1
      • Q Qt embedded developer

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

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

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

          Q Offline
          Q Offline
          Qt embedded developer
          wrote on last edited by Qt embedded developer
          #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
          • Christian EhrlicherC Christian Ehrlicher

            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 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 ?

            JonBJ 1 Reply Last reply
            0
            • Q Qt embedded developer

              @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 ?

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

                @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 last edited by Qt embedded developer
                #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

                JonBJ jsulmJ 2 Replies Last reply
                0
                • Axel SpoerlA Offline
                  Axel SpoerlA Offline
                  Axel Spoerl
                  Moderators
                  wrote on 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

                    @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

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

                      @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

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 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

                      JonBJ 1 Reply Last reply
                      1
                      • jsulmJ jsulm

                        @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...

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on 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

                        • Login

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