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. exe file replace using QProcess

exe file replace using QProcess

Scheduled Pinned Locked Moved Solved General and Desktop
29 Posts 5 Posters 8.9k 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.
  • 4 Offline
    4 Offline
    4j1th
    wrote on 14 Dec 2015, 17:06 last edited by
    #1

    I am trying to update my soft. itself in windows, I can't replace a running exe itself with in so I try to do it by using QProcess.

    QString currentpath = QDir::currentPath()+"/mySoft.exe.tmp";
    currentpath = QDir::toNativeSeparators(currentpath);
    qDebug() << currentpath;
    QProcess* process = new QProcess(this);
    process->start("del", QStringList() << currentpath);
    qDebug() << process->errorString();
    
    connect(process, SIGNAL(finished(int,QProcess::ExitStatus)),
            this, SLOT(processFinished()));
    

    But I got an error while running Process failed to start: No such file or directory

    Pardon my English
    Thank you.

    1 Reply Last reply
    0
    • 4 Offline
      4 Offline
      4j1th
      wrote on 14 Dec 2015, 17:22 last edited by
      #2

      In linux I replace del with rm it works fine

      Pardon my English
      Thank you.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 14 Dec 2015, 17:39 last edited by
        #3

        Hi
        in linux the exe is not locked but I believe it is in windows.
        Have you tried deleting it manually with explorer?

        4 1 Reply Last reply 14 Dec 2015, 18:03
        0
        • M mrjj
          14 Dec 2015, 17:39

          Hi
          in linux the exe is not locked but I believe it is in windows.
          Have you tried deleting it manually with explorer?

          4 Offline
          4 Offline
          4j1th
          wrote on 14 Dec 2015, 18:03 last edited by
          #4

          @mrjj
          my linux code is

          QProcess* process = new QProcess(this);
          process->start("rm", QStringList() << "mysoft");
          connect(process, SIGNAL(finished(int,QProcess::ExitStatus)),
                                      this, SLOT(processFinished()));
          

          tried the same path with del in cmd and it works fine

          Pardon my English
          Thank you.

          M 1 Reply Last reply 14 Dec 2015, 18:13
          0
          • 4 4j1th
            14 Dec 2015, 18:03

            @mrjj
            my linux code is

            QProcess* process = new QProcess(this);
            process->start("rm", QStringList() << "mysoft");
            connect(process, SIGNAL(finished(int,QProcess::ExitStatus)),
                                        this, SLOT(processFinished()));
            

            tried the same path with del in cmd and it works fine

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 14 Dec 2015, 18:13 last edited by
            #5

            @4j1th said:
            Ok. never tried to delete running exe :)
            I wonder about the name
            "mySoft.exe.tmp"

            Why .tmp?

            4 1 Reply Last reply 14 Dec 2015, 18:34
            0
            • M mrjj
              14 Dec 2015, 18:13

              @4j1th said:
              Ok. never tried to delete running exe :)
              I wonder about the name
              "mySoft.exe.tmp"

              Why .tmp?

              4 Offline
              4 Offline
              4j1th
              wrote on 14 Dec 2015, 18:34 last edited by
              #6

              @mrjj download a new version from server and save it in mysoft.exe.tmp then remove mysoft.exe then rename mysoft.exe.tmp to mysoft.exe. I tried this method because in this way I don't want to create another program for updating.

              I just try to delete another file in the same dir but the same error, then try to delete an image file in home dir it also give the same error. I think 't's not about the permission. also tried using DEL /F /Q /A <File Path>

              Pardon my English
              Thank you.

              M 1 Reply Last reply 14 Dec 2015, 18:37
              0
              • 4 4j1th
                14 Dec 2015, 18:34

                @mrjj download a new version from server and save it in mysoft.exe.tmp then remove mysoft.exe then rename mysoft.exe.tmp to mysoft.exe. I tried this method because in this way I don't want to create another program for updating.

                I just try to delete another file in the same dir but the same error, then try to delete an image file in home dir it also give the same error. I think 't's not about the permission. also tried using DEL /F /Q /A <File Path>

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 14 Dec 2015, 18:37 last edited by
                #7

                @4j1th
                Maybe its something basic ?
                Like spaces in file path ?

                4 1 Reply Last reply 14 Dec 2015, 18:44
                0
                • M mrjj
                  14 Dec 2015, 18:37

                  @4j1th
                  Maybe its something basic ?
                  Like spaces in file path ?

                  4 Offline
                  4 Offline
                  4j1th
                  wrote on 14 Dec 2015, 18:44 last edited by
                  #8

                  @mrjj use the out from qDebug() << currentpath; then run it on cmd works

                  Pardon my English
                  Thank you.

                  M 1 Reply Last reply 14 Dec 2015, 18:46
                  0
                  • 4 4j1th
                    14 Dec 2015, 18:44

                    @mrjj use the out from qDebug() << currentpath; then run it on cmd works

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 14 Dec 2015, 18:46 last edited by mrjj
                    #9

                    @4j1th
                    Hmm. i think might need to run cmd also as del is part of command.exe.
                    http://stackoverflow.com/questions/21596104/how-to-execute-a-cmd-command-using-qprocess
                    he uses "cmd"
                    something like
                    process->start("cmd", QStringList() << "del " << currentpath);
                    maybe ?

                    kshegunovK 4 2 Replies Last reply 14 Dec 2015, 18:51
                    1
                    • M mrjj
                      14 Dec 2015, 18:46

                      @4j1th
                      Hmm. i think might need to run cmd also as del is part of command.exe.
                      http://stackoverflow.com/questions/21596104/how-to-execute-a-cmd-command-using-qprocess
                      he uses "cmd"
                      something like
                      process->start("cmd", QStringList() << "del " << currentpath);
                      maybe ?

                      kshegunovK Offline
                      kshegunovK Offline
                      kshegunov
                      Moderators
                      wrote on 14 Dec 2015, 18:51 last edited by
                      #10

                      @4j1th said:

                      I am trying to update my soft. itself in windows, I can't replace a running exe itself with in so I try to do it by using QProcess.

                      You can't, the OS will lock the file and will not allow you to modify it. It doesn't matter if you use QProcess or cmd, or explorer, it will not work.

                      Read and abide by the Qt Code of Conduct

                      4 1 Reply Last reply 14 Dec 2015, 19:16
                      1
                      • M mrjj
                        14 Dec 2015, 18:46

                        @4j1th
                        Hmm. i think might need to run cmd also as del is part of command.exe.
                        http://stackoverflow.com/questions/21596104/how-to-execute-a-cmd-command-using-qprocess
                        he uses "cmd"
                        something like
                        process->start("cmd", QStringList() << "del " << currentpath);
                        maybe ?

                        4 Offline
                        4 Offline
                        4j1th
                        wrote on 14 Dec 2015, 19:07 last edited by
                        #11

                        @mrjj no luck it can't delete any file

                        Pardon my English
                        Thank you.

                        1 Reply Last reply
                        0
                        • kshegunovK kshegunov
                          14 Dec 2015, 18:51

                          @4j1th said:

                          I am trying to update my soft. itself in windows, I can't replace a running exe itself with in so I try to do it by using QProcess.

                          You can't, the OS will lock the file and will not allow you to modify it. It doesn't matter if you use QProcess or cmd, or explorer, it will not work.

                          4 Offline
                          4 Offline
                          4j1th
                          wrote on 14 Dec 2015, 19:16 last edited by 4j1th
                          #12

                          @kshegunov so you're suggesting me to write another programme to run update

                          But this idea works on linux.

                          Pardon my English
                          Thank you.

                          M 1 Reply Last reply 14 Dec 2015, 19:19
                          0
                          • 4 4j1th
                            14 Dec 2015, 19:16

                            @kshegunov so you're suggesting me to write another programme to run update

                            But this idea works on linux.

                            M Offline
                            M Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 14 Dec 2015, 19:19 last edited by
                            #13

                            @4j1th
                            Hi
                            just tested in win 7.
                            it wont allow to delete running exe.

                            Linux will, i know. but Windows wont allow.

                            4 1 Reply Last reply 14 Dec 2015, 19:26
                            0
                            • M mrjj
                              14 Dec 2015, 19:19

                              @4j1th
                              Hi
                              just tested in win 7.
                              it wont allow to delete running exe.

                              Linux will, i know. but Windows wont allow.

                              4 Offline
                              4 Offline
                              4j1th
                              wrote on 14 Dec 2015, 19:26 last edited by
                              #14

                              @mrjj can you delete any other file, I can't do it either

                              Pardon my English
                              Thank you.

                              M 1 Reply Last reply 14 Dec 2015, 19:31
                              1
                              • 4 4j1th
                                14 Dec 2015, 19:26

                                @mrjj can you delete any other file, I can't do it either

                                M Offline
                                M Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on 14 Dec 2015, 19:31 last edited by
                                #15

                                @4j1th
                                hi

                                 QProcess process;
                                    process.start("cmd", QStringList() <<"/C" << "del" << "e:/test.txt " );
                                

                                this delete the file i put on e:\

                                4 1 Reply Last reply 14 Dec 2015, 19:47
                                1
                                • M mrjj
                                  14 Dec 2015, 19:31

                                  @4j1th
                                  hi

                                   QProcess process;
                                      process.start("cmd", QStringList() <<"/C" << "del" << "e:/test.txt " );
                                  

                                  this delete the file i put on e:\

                                  4 Offline
                                  4 Offline
                                  4j1th
                                  wrote on 14 Dec 2015, 19:47 last edited by
                                  #16

                                  @mrjj @kshegunov

                                  you're right, can't replace running exe, so I think the best way to update is write an another app for updation right?

                                  Pardon my English
                                  Thank you.

                                  M 1 Reply Last reply 14 Dec 2015, 19:51
                                  1
                                  • 4 4j1th
                                    14 Dec 2015, 19:47

                                    @mrjj @kshegunov

                                    you're right, can't replace running exe, so I think the best way to update is write an another app for updation right?

                                    M Offline
                                    M Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on 14 Dec 2015, 19:51 last edited by
                                    #17

                                    @4j1th
                                    Well even another program cannot override the exe, so the updater must
                                    close the running version.

                                    4 1 Reply Last reply 14 Dec 2015, 19:57
                                    1
                                    • M mrjj
                                      14 Dec 2015, 19:51

                                      @4j1th
                                      Well even another program cannot override the exe, so the updater must
                                      close the running version.

                                      4 Offline
                                      4 Offline
                                      4j1th
                                      wrote on 14 Dec 2015, 19:57 last edited by
                                      #18

                                      @mrjj Thank you for your help, this is the second time you help me like a guru

                                      Thank you

                                      Pardon my English
                                      Thank you.

                                      M 1 Reply Last reply 14 Dec 2015, 20:01
                                      0
                                      • 4 4j1th
                                        14 Dec 2015, 19:57

                                        @mrjj Thank you for your help, this is the second time you help me like a guru

                                        Thank you

                                        M Offline
                                        M Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on 14 Dec 2015, 20:01 last edited by
                                        #19

                                        @4j1th
                                        You are most welcome :)
                                        The exe you are trying to update. is it your own program?

                                        4 1 Reply Last reply 14 Dec 2015, 20:02
                                        0
                                        • M mrjj
                                          14 Dec 2015, 20:01

                                          @4j1th
                                          You are most welcome :)
                                          The exe you are trying to update. is it your own program?

                                          4 Offline
                                          4 Offline
                                          4j1th
                                          wrote on 14 Dec 2015, 20:02 last edited by
                                          #20

                                          @mrjj yes

                                          Pardon my English
                                          Thank you.

                                          M 1 Reply Last reply 14 Dec 2015, 20:04
                                          0

                                          1/29

                                          14 Dec 2015, 17:06

                                          • Login

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