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. close/kill another Windows process which is started by run a .bat in Qt app

close/kill another Windows process which is started by run a .bat in Qt app

Scheduled Pinned Locked Moved Unsolved General and Desktop
19 Posts 4 Posters 1.4k 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.
  • O Offline
    O Offline
    opengpu
    wrote on 10 Jun 2019, 07:10 last edited by
    #1

    any way to close/kill another Windows process which is started by run a .bat in Qt app?

    J J 2 Replies Last reply 11 Jun 2019, 05:20
    0
    • O opengpu
      10 Jun 2019, 07:10

      any way to close/kill another Windows process which is started by run a .bat in Qt app?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 11 Jun 2019, 05:20 last edited by
      #2

      @opengpu I guess you're using QProcess (you did not say how you're starting the process).
      If so what about:

      • https://doc.qt.io/qt-5/qprocess.html#close
      • https://doc.qt.io/qt-5/qprocess.html#kill
      • https://doc.qt.io/qt-5/qprocess.html#terminate

      ?

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

      1 Reply Last reply
      4
      • O opengpu
        10 Jun 2019, 07:10

        any way to close/kill another Windows process which is started by run a .bat in Qt app?

        J Offline
        J Offline
        JonB
        wrote on 11 Jun 2019, 07:29 last edited by JonB 6 Nov 2019, 07:29
        #3

        @opengpu
        Provided you mean the Windows process started from the BAT responds to the BAT being terminated then as @jsulm says you should be able to terminate it by terminating the QProcess used to launch the BAT. However, if the sub-process has "gone interactive" and the BAT file is not waiting for it (e.g. run notepad.exe or start from a BAT), you will have to find the sub-process and kill that (e.g. taskkill.exe, EnumProcesses).

        1 Reply Last reply
        4
        • V Offline
          V Offline
          Vijaykarthikeyan
          wrote on 3 May 2024, 10:26 last edited by
          #4

          QString command
          = "gst-launch-1.0 -v ksvideosrc device-index=0 ! video/x-raw,framerate=30/1 ! "
          "videoconvert ! queue ! jpegenc ! rtpjpegpay ! udpsink host=127.0.0.1 port=5200 "
          "autoaudiosrc ! audioconvert ! audioresample ! opusenc ! rtpopuspay ! udpsink "
          "host=127.0.0.1 port=5202 "; // Reads the first line from the file
          process->start("cmd.exe", QStringList() << "/c" << command);

          How to end the process.. process->kill() or terminate() will only close the process running status..but not the process it opened..what is the proper way to close the cmd.exe in Qt

          J 1 Reply Last reply 3 May 2024, 10:34
          0
          • V Vijaykarthikeyan
            3 May 2024, 10:26

            QString command
            = "gst-launch-1.0 -v ksvideosrc device-index=0 ! video/x-raw,framerate=30/1 ! "
            "videoconvert ! queue ! jpegenc ! rtpjpegpay ! udpsink host=127.0.0.1 port=5200 "
            "autoaudiosrc ! audioconvert ! audioresample ! opusenc ! rtpopuspay ! udpsink "
            "host=127.0.0.1 port=5202 "; // Reads the first line from the file
            process->start("cmd.exe", QStringList() << "/c" << command);

            How to end the process.. process->kill() or terminate() will only close the process running status..but not the process it opened..what is the proper way to close the cmd.exe in Qt

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 3 May 2024, 10:34 last edited by
            #5

            @Vijaykarthikeyan said in close/kill another Windows process which is started by run a .bat in Qt app:

            gst-launch

            Why do you need it at all? If you read https://gstreamer.freedesktop.org/documentation/tools/gst-launch.html?gi-language=c you will find this:
            "Please note that gst-launch-1.0 is primarily a debugging tool. You should not build applications on top of it. For applications, use the gst_parse_launch() function of the GStreamer API as an easy way to construct pipelines from pipeline descriptions."

            And I also don't think you need cmd.exe here. Why don't you simply start gst-launch-1.0?

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

            V 1 Reply Last reply 3 May 2024, 11:47
            1
            • J jsulm
              3 May 2024, 10:34

              @Vijaykarthikeyan said in close/kill another Windows process which is started by run a .bat in Qt app:

              gst-launch

              Why do you need it at all? If you read https://gstreamer.freedesktop.org/documentation/tools/gst-launch.html?gi-language=c you will find this:
              "Please note that gst-launch-1.0 is primarily a debugging tool. You should not build applications on top of it. For applications, use the gst_parse_launch() function of the GStreamer API as an easy way to construct pipelines from pipeline descriptions."

              And I also don't think you need cmd.exe here. Why don't you simply start gst-launch-1.0?

              V Offline
              V Offline
              Vijaykarthikeyan
              wrote on 3 May 2024, 11:47 last edited by Vijaykarthikeyan 5 Mar 2024, 11:50
              #6

              @jsulm Thanks for your kind reply.. The reason why I'm trying to run Gstreamer command is that I'm having trouble to link gstreamer Libraries inside qt .pro file. It's the big thing and I'm very tired of linking..[trying for almost 5 months]. If I want to use
              gst_parse_launch(), I have to include gst library and header files that is what I'm struggling with.

              So, I tried to run the command prompt using QProcess. Opening the Command Prompt using QProcess is successful.But,I dont know how to kill that cmd.exe . Is there any way to get PId to end the process

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 3 May 2024, 11:51 last edited by
                #7

                I asked above why you need cmd.exe at all?

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

                V 1 Reply Last reply 3 May 2024, 11:53
                0
                • J jsulm
                  3 May 2024, 11:51

                  I asked above why you need cmd.exe at all?

                  V Offline
                  V Offline
                  Vijaykarthikeyan
                  wrote on 3 May 2024, 11:53 last edited by
                  #8

                  @jsulm To Run the Gstreamer command via Qt Applciation..sir

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 3 May 2024, 12:12 last edited by
                    #9

                    You can run this command without cmd.exe, that's my point...

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

                    V 1 Reply Last reply 3 May 2024, 12:27
                    2
                    • J jsulm
                      3 May 2024, 12:12

                      You can run this command without cmd.exe, that's my point...

                      V Offline
                      V Offline
                      Vijaykarthikeyan
                      wrote on 3 May 2024, 12:27 last edited by
                      #10

                      @jsulm With the help of GStreamer Library?

                      J 1 Reply Last reply 3 May 2024, 12:29
                      0
                      • J Offline
                        J Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on 3 May 2024, 12:29 last edited by
                        #11

                        No.

                        process->start("gst-launch-1.0", QStringList() << HERE_PUT_THE_PARAMETERS_AS_LIST);
                        

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

                        1 Reply Last reply
                        2
                        • V Vijaykarthikeyan
                          3 May 2024, 12:27

                          @jsulm With the help of GStreamer Library?

                          J Offline
                          J Offline
                          JonB
                          wrote on 3 May 2024, 12:29 last edited by JonB 5 Mar 2024, 12:43
                          #12

                          @Vijaykarthikeyan
                          Don't understand. @jsulm is just asking why you use cmd /c ... at all? Use QProcess::startCommand() directly on your string starting with "gst-launch-1.0 ...". Then you don't have a cmd process and a gst-launch-1.0 one to deal with.

                          @jsulm
                          The user probably doesn't want to split his string into lots of separate arguments to pass to start() :) That's why I suggest he might want to use startCommand().

                          V 2 Replies Last reply 3 May 2024, 12:42
                          1
                          • J JonB
                            3 May 2024, 12:29

                            @Vijaykarthikeyan
                            Don't understand. @jsulm is just asking why you use cmd /c ... at all? Use QProcess::startCommand() directly on your string starting with "gst-launch-1.0 ...". Then you don't have a cmd process and a gst-launch-1.0 one to deal with.

                            @jsulm
                            The user probably doesn't want to split his string into lots of separate arguments to pass to start() :) That's why I suggest he might want to use startCommand().

                            V Offline
                            V Offline
                            Vijaykarthikeyan
                            wrote on 3 May 2024, 12:42 last edited by
                            #13

                            @JonB Oh..sorry..actually..I dont know about startcommand() until now..I'll try it and feedback you

                            1 Reply Last reply
                            0
                            • J JonB
                              3 May 2024, 12:29

                              @Vijaykarthikeyan
                              Don't understand. @jsulm is just asking why you use cmd /c ... at all? Use QProcess::startCommand() directly on your string starting with "gst-launch-1.0 ...". Then you don't have a cmd process and a gst-launch-1.0 one to deal with.

                              @jsulm
                              The user probably doesn't want to split his string into lots of separate arguments to pass to start() :) That's why I suggest he might want to use startCommand().

                              V Offline
                              V Offline
                              Vijaykarthikeyan
                              wrote on 3 May 2024, 12:47 last edited by
                              #14

                              @JonB Sorry to interrupt you..Just now gone throught that documentation,this startCommand() method is available for the Qt versions 6.x but I'm using 5.15.2.

                              that's why i didnt know about this command

                              1 Reply Last reply
                              0
                              • J Offline
                                J Offline
                                JonB
                                wrote on 3 May 2024, 12:54 last edited by JonB 5 Mar 2024, 12:55
                                #15

                                Always helps if you tells which version you are using for any question!

                                To use start() then (without cmd /c) you must chop your line up into separate arguments at every (non-embedded) space. probably including each of those ! which are being used as "pipes" on the command passed to gst-launch-1.0. Do so manually in code source, or maybe use QString::split() on space if you want. I think QStringList QProcess::splitCommand(QStringView command) is available to you in 5.15. [Yes, it was introduced at 5.15 if you want to use it.]

                                V 1 Reply Last reply 3 May 2024, 13:20
                                2
                                • J JonB
                                  3 May 2024, 12:54

                                  Always helps if you tells which version you are using for any question!

                                  To use start() then (without cmd /c) you must chop your line up into separate arguments at every (non-embedded) space. probably including each of those ! which are being used as "pipes" on the command passed to gst-launch-1.0. Do so manually in code source, or maybe use QString::split() on space if you want. I think QStringList QProcess::splitCommand(QStringView command) is available to you in 5.15. [Yes, it was introduced at 5.15 if you want to use it.]

                                  V Offline
                                  V Offline
                                  Vijaykarthikeyan
                                  wrote on 3 May 2024, 13:20 last edited by
                                  #16

                                  @JonB Ok..Running..But..when process->kill() executed..it is not closing that process.Why? How to close it by process->processId()

                                  1 Reply Last reply
                                  0
                                  • J Offline
                                    J Offline
                                    JonB
                                    wrote on 3 May 2024, 13:58 last edited by
                                    #17

                                    Why? I don't know.
                                    Windows/DOS has a taskkill <pid> command, I believe. You could issue that via another QProcess (try it first from command line). I don't know if that will work when QProcess::kill() does not. I do not know whether gst-launch-1.0 is itself a "wrapper" for spawning other processes.

                                    V 1 Reply Last reply 3 May 2024, 14:02
                                    1
                                    • J JonB
                                      3 May 2024, 13:58

                                      Why? I don't know.
                                      Windows/DOS has a taskkill <pid> command, I believe. You could issue that via another QProcess (try it first from command line). I don't know if that will work when QProcess::kill() does not. I do not know whether gst-launch-1.0 is itself a "wrapper" for spawning other processes.

                                      V Offline
                                      V Offline
                                      Vijaykarthikeyan
                                      wrote on 3 May 2024, 14:02 last edited by
                                      #18

                                      @JonB ok..understand..Can you please calrify one thing.. Will terminatinf the QProcess will terminate the process pointer or the process which is triggered by the QProcess?

                                      J 1 Reply Last reply 3 May 2024, 14:52
                                      0
                                      • V Vijaykarthikeyan
                                        3 May 2024, 14:02

                                        @JonB ok..understand..Can you please calrify one thing.. Will terminatinf the QProcess will terminate the process pointer or the process which is triggered by the QProcess?

                                        J Offline
                                        J Offline
                                        JonB
                                        wrote on 3 May 2024, 14:52 last edited by JonB 5 Apr 2024, 08:06
                                        #19

                                        @Vijaykarthikeyan It should delete terminate the process created on the QProcess object, i.e. just what you would expect.

                                        1 Reply Last reply
                                        1

                                        • Login

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