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
?
-
@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
). -
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?
-
@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?
-
You can run this command without cmd.exe, that's my point...
-
No.
process->start("gst-launch-1.0", QStringList() << HERE_PUT_THE_PARAMETERS_AS_LIST);
-
@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()
. -
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.] -
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. -
@Vijaykarthikeyan It should
deleteterminate the process created on theQProcess
object, i.e. just what you would expect.