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. QProcess not working.
Forum Updated to NodeBB v4.3 + New Features

QProcess not working.

Scheduled Pinned Locked Moved Solved General and Desktop
29 Posts 5 Posters 3.9k 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.
  • jsulmJ jsulm

    @SPlatten Did you notice "EDIT: do NOT add redirection in slstArguments !!!" in @KroMignon post?
    Why do you need redirection to a file if you can simply read the stdout from the process as @KroMignon already suggested?

    SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #19

    @jsulm The purpose of this is to provide an export / backup facility of the database to an SQL file.

    Kind Regards,
    Sy

    jsulmJ 1 Reply Last reply
    0
    • SPlattenS SPlatten

      @jsulm The purpose of this is to provide an export / backup facility of the database to an SQL file.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #20

      @SPlatten You can still write the stdout from the process to a file...

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

      1 Reply Last reply
      0
      • KroMignonK KroMignon

        @SPlatten This don't make sense to me:

        • Why do you add application into argument list?
        • Why to you redirect it to a file and not directly read it for QProcess stream?
        SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by
        #21

        @KroMignon , as I said earlier I've tried numerous things, thats just one of variant.

        Kind Regards,
        Sy

        jsulmJ 1 Reply Last reply
        0
        • SPlattenS SPlatten

          @KroMignon , as I said earlier I've tried numerous things, thats just one of variant.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #22

          @SPlatten Also, as @JonB already wrote: you can't use redirection without a shell. Redirection is a feature of a shell (cmd.exe on Windows). So, you will need to execute cmd.exe as executable and pass everything else as parameters.

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

          1 Reply Last reply
          0
          • JonBJ JonB

            @SPlatten
            int QProcess::execute(const QString &program, const QStringList &arguments) [static]. So it's execute. It was introduced into some Qt. I don't know about 5.9.2.

            As I said, forget I ever wrote exec or execute. The same argument processing applies to QProcess::start. You keep passing > argument, and I've explained this won't work.

            SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by
            #23

            @JonB , just tried:

            QProcess::execute(strApp);
            

            strApp contains:

            /c "C:/Program Files (x86)/MariaDB 10.5/bin/mysqldump" --host=localhost --user=trainer --password=CobhamAC training > C:/Users/simon.platten/Documents/TrainerS1D5.sql
            

            Still not working.

            Kind Regards,
            Sy

            jsulmJ JonBJ 2 Replies Last reply
            0
            • KroMignonK KroMignon

              @SPlatten said in QProcess not working.:

              I don't follow you, if I copy the command line and arguments to a command prompt it works, the arguments are everything it needs for mysqldump to connect and export the database.

              With QProcess, you don't start the process from a shell / command prompt, that is the difference here.
              Try this:

              auto proc = new QProcess;
              QObject::connect(proc, &QProcess::stateChanged,
                                  [proc](QProcess::ProcessState newState)
              {
                  qDebug() << "new state is " <<  newState;
                  if(newState == QProcess::NotRunning)
                  {
                      QString output(proc->readAll());
                      qDebug() << "Output is" << output;
                      proc->delateLater();
                  }
              });
              proc->setWorkingDirectory(strDBinstFolder);
              proc->start(strApp,slstArguments );
              

              EDIT: do NOT add redirection in slstArguments !!!

              EDIT BIS:

              QStringList slstArguments;
              slstArguments << (QString(DataSets::mscszOptionHost) + Trainer::strHost())
                                            << (QString(DataSets::mscszOptionUser) + Trainer::strUser())
                                            << (QString(DataSets::mscszOptionPassword) + Trainer::strPassword())
                                            << (Trainer::strDatabase());
              

              ==> I suppose that DataSets::mscszOptionHost contains --host=

              SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on last edited by
              #24

              @KroMignon , yes it does, I'll try without the application which is where I started.

              Kind Regards,
              Sy

              1 Reply Last reply
              0
              • SPlattenS SPlatten

                @JonB , just tried:

                QProcess::execute(strApp);
                

                strApp contains:

                /c "C:/Program Files (x86)/MariaDB 10.5/bin/mysqldump" --host=localhost --user=trainer --password=CobhamAC training > C:/Users/simon.platten/Documents/TrainerS1D5.sql
                

                Still not working.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by jsulm
                #25

                @SPlatten said in QProcess not working.:

                QProcess::execute(strApp);

                First parameter is the executable ("cmd.exe" in your case), second is a list of parameters...

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

                1 Reply Last reply
                0
                • SPlattenS SPlatten

                  @JonB , just tried:

                  QProcess::execute(strApp);
                  

                  strApp contains:

                  /c "C:/Program Files (x86)/MariaDB 10.5/bin/mysqldump" --host=localhost --user=trainer --password=CobhamAC training > C:/Users/simon.platten/Documents/TrainerS1D5.sql
                  

                  Still not working.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #26

                  @SPlatten
                  No, that is not what I said at all. Look at the example. The program needs to be cmd.exe. The arguments need to be first /c and second your whole command line (as a single argument; for cmd it doesn't seem to matter if you pass it as one string as I showed, or I think it will accept each argument separately). I showed you earlier an example of what you need.

                  SPlattenS 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @SPlatten
                    No, that is not what I said at all. Look at the example. The program needs to be cmd.exe. The arguments need to be first /c and second your whole command line (as a single argument; for cmd it doesn't seem to matter if you pass it as one string as I showed, or I think it will accept each argument separately). I showed you earlier an example of what you need.

                    SPlattenS Offline
                    SPlattenS Offline
                    SPlatten
                    wrote on last edited by SPlatten
                    #27

                    @JonB , ok, having prefixed with cmd.exe it now works. Thank you, thank you everyone.

                    Kind Regards,
                    Sy

                    JonBJ 1 Reply Last reply
                    1
                    • SPlattenS SPlatten

                      @JonB , ok, having prefixed with cmd.exe it now works. Thank you, thank you everyone.

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #28

                      @SPlatten
                      Having said that. If the only purpose of having to go via cmd /c is to handle the redirection of output via >, I would handle that back in QProcess (I think others have suggested this) and then you won't need to go via cmd, which has its disadvantages.

                      SPlattenS 1 Reply Last reply
                      1
                      • JonBJ JonB

                        @SPlatten
                        Having said that. If the only purpose of having to go via cmd /c is to handle the redirection of output via >, I would handle that back in QProcess (I think others have suggested this) and then you won't need to go via cmd, which has its disadvantages.

                        SPlattenS Offline
                        SPlattenS Offline
                        SPlatten
                        wrote on last edited by
                        #29

                        @JonB I will investigate now.

                        Kind Regards,
                        Sy

                        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