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. Can't kill/terminate batch process
Forum Updated to NodeBB v4.3 + New Features

Can't kill/terminate batch process

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 2 Posters 2.3k 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.
  • E Offline
    E Offline
    enekow
    wrote on last edited by enekow
    #1

    Hello,

    I'm running a batch file using QProcess.start().
    Because is a .bat file, the only way I found is executing this way:
    process.start("cmd.exe", QStringList() << "/c" << "path/to/bat/file.bat"); (this line was edited)

    The process works properly, but I am not capable to terminate the process.
    I tried with process.terminate() and process.kill().
    (It says "invalid thread identifier")

    Any idea?
    thnks!

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

      Hi
      But if file.bat do not contain pause or anything interactive
      are you sure its not already terminated ?

      Also the correct way is to do
      process.start("cmd.exe", QStringList() << "/c" << "path/to/bat/file.bat" );
      so each parameter is in its own index.

      1 Reply Last reply
      4
      • E Offline
        E Offline
        enekow
        wrote on last edited by
        #3

        Thanks for your response @mrjj

        @mrjj said in Can't kill/terminate batch process:

        process.start("cmd.exe", QStringList() << "/c" << "path/to/bat/file.bat" );

        You are right. It is done like that, I just put it wrong in the example above. (I will edit)

        @mrjj said in Can't kill/terminate batch process:

        But if file.bat do not contain pause or anything interactive
        are you sure its not already terminated ?

        I think you are right. The batch file launches another process and that is the process I am trying to close, not the batch process itself. Lets see how can I reach that other process...

        Thanks!

        mrjjM 1 Reply Last reply
        0
        • E enekow

          Thanks for your response @mrjj

          @mrjj said in Can't kill/terminate batch process:

          process.start("cmd.exe", QStringList() << "/c" << "path/to/bat/file.bat" );

          You are right. It is done like that, I just put it wrong in the example above. (I will edit)

          @mrjj said in Can't kill/terminate batch process:

          But if file.bat do not contain pause or anything interactive
          are you sure its not already terminated ?

          I think you are right. The batch file launches another process and that is the process I am trying to close, not the batch process itself. Lets see how can I reach that other process...

          Thanks!

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @enekow

          How do you start the second process ?
          If possible, you can return the PID from bat file and run taskkill from Qt to get rid of it depending on your
          actual use case :)

          1 Reply Last reply
          2
          • E Offline
            E Offline
            enekow
            wrote on last edited by
            #5

            @mrjj said in Can't kill/terminate batch process:

            How do you start the second process ?

            I'm not very sure, since I never opened a .bat file before.
            Getting the process id would be the best way, however I'm not sure if I'm "allowed " to change that file...

            Thanks for your help!

            mrjjM 1 Reply Last reply
            0
            • E enekow

              @mrjj said in Can't kill/terminate batch process:

              How do you start the second process ?

              I'm not very sure, since I never opened a .bat file before.
              Getting the process id would be the best way, however I'm not sure if I'm "allowed " to change that file...

              Thanks for your help!

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @enekow

              Hi. a bat file is just a text file.
              if you cant edit the bat file (change it to return pid)
              then you can see name of other process.
              taskkill can use names too.

              Is there a reason the second process must be stopped/killed ?
              it wont ever exit on its own?

              1 Reply Last reply
              0
              • E Offline
                E Offline
                enekow
                wrote on last edited by
                #7

                The issue is that the .bat file together with the process it launches is an external application, and it should work as it is. (That's why I'm not "allowed" to change it)

                The second process is a database, so it should be running until I wanted it closed.

                mrjjM 1 Reply Last reply
                0
                • E enekow

                  The issue is that the .bat file together with the process it launches is an external application, and it should work as it is. (That's why I'm not "allowed" to change it)

                  The second process is a database, so it should be running until I wanted it closed.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @enekow

                  If its a database server/service you want to forcefully close/kill, make sure its
                  setup to not freak out :)

                  1 Reply Last reply
                  1
                  • E Offline
                    E Offline
                    enekow
                    wrote on last edited by
                    #9

                    @mrjj sure! Thanks for your help!

                    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