Can't kill/terminate batch process
-
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 withprocess.terminate()
andprocess.kill()
.
(It says "invalid thread identifier")Any idea?
thnks! -
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. -
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!
-
@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!
-
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? -