close/kill another Windows process which is started by run a .bat in Qt app
-
wrote on 10 Jun 2019, 07:10 last edited by
any way to close/kill another Windows process which is started by run a .bat in Qt app?
-
@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
?
-
wrote on 11 Jun 2019, 07:29 last edited by JonB 6 Nov 2019, 07:29
@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 theQProcess
used to launch the BAT. However, if the sub-process has "gone interactive" and the BAT file is not waiting for it (e.g. runnotepad.exe
orstart
from a BAT), you will have to find the sub-process and kill that (e.g.taskkill.exe
,EnumProcesses
). -
wrote on 3 May 2024, 10:26 last edited by
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
-
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
@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?
-
@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?
wrote on 3 May 2024, 11:47 last edited by Vijaykarthikeyan 5 Mar 2024, 11:50@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
-
I asked above why you need cmd.exe at all?
-
wrote on 3 May 2024, 11:53 last edited by
@jsulm To Run the Gstreamer command via Qt Applciation..sir
-
You can run this command without cmd.exe, that's my point...
-
wrote on 3 May 2024, 12:27 last edited by
@jsulm With the help of GStreamer Library?
-
No.
process->start("gst-launch-1.0", QStringList() << HERE_PUT_THE_PARAMETERS_AS_LIST);
-
@jsulm With the help of GStreamer Library?
wrote on 3 May 2024, 12:29 last edited by JonB 5 Mar 2024, 12:43@Vijaykarthikeyan
Don't understand. @jsulm is just asking why you usecmd /c ...
at all? Use QProcess::startCommand() directly on your string starting with"gst-launch-1.0 ..."
. Then you don't have acmd
process and agst-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 tostart()
:) That's why I suggest he might want to usestartCommand()
. -
@Vijaykarthikeyan
Don't understand. @jsulm is just asking why you usecmd /c ...
at all? Use QProcess::startCommand() directly on your string starting with"gst-launch-1.0 ..."
. Then you don't have acmd
process and agst-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 tostart()
:) That's why I suggest he might want to usestartCommand()
.wrote on 3 May 2024, 12:42 last edited by@JonB Oh..sorry..actually..I dont know about startcommand() until now..I'll try it and feedback you
-
@Vijaykarthikeyan
Don't understand. @jsulm is just asking why you usecmd /c ...
at all? Use QProcess::startCommand() directly on your string starting with"gst-launch-1.0 ..."
. Then you don't have acmd
process and agst-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 tostart()
:) That's why I suggest he might want to usestartCommand()
.wrote on 3 May 2024, 12:47 last edited by@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
-
wrote on 3 May 2024, 12:54 last edited by JonB 5 Mar 2024, 12:55
Always helps if you tells which version you are using for any question!
To use
start()
then (withoutcmd /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 togst-launch-1.0
. Do so manually in code source, or maybe useQString::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.] -
Always helps if you tells which version you are using for any question!
To use
start()
then (withoutcmd /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 togst-launch-1.0
. Do so manually in code source, or maybe useQString::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.]wrote on 3 May 2024, 13:20 last edited by@JonB Ok..Running..But..when process->kill() executed..it is not closing that process.Why? How to close it by process->processId()
-
wrote on 3 May 2024, 13:58 last edited by
Why? I don't know.
Windows/DOS has ataskkill <pid>
command, I believe. You could issue that via anotherQProcess
(try it first from command line). I don't know if that will work whenQProcess::kill()
does not. I do not know whethergst-launch-1.0
is itself a "wrapper" for spawning other processes. -
Why? I don't know.
Windows/DOS has ataskkill <pid>
command, I believe. You could issue that via anotherQProcess
(try it first from command line). I don't know if that will work whenQProcess::kill()
does not. I do not know whethergst-launch-1.0
is itself a "wrapper" for spawning other processes.wrote on 3 May 2024, 14:02 last edited by@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?
-
@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?
wrote on 3 May 2024, 14:52 last edited by JonB 5 Apr 2024, 08:06@Vijaykarthikeyan It should
deleteterminate the process created on theQProcess
object, i.e. just what you would expect.