PietR26
PietR26

Reputation: 25

How to kill a process with QProcess::execute()?

I've some problems with killing a process using taskkill.

My code:

QStringList args;
args << "/F";
args << "/IM testApp.exe";
QProcess::execute("taskkill", args); //Should be 'taskkill /IM testApp.exe /F'

Output (translated from german):

ERROR: Invalid argument - "/IM testApp.exe".
Type "TASKKILL /?" to show the syntax.

Upvotes: 1

Views: 553

Answers (1)

3CxEZiVlQ
3CxEZiVlQ

Reputation: 38332

"/IM testApp.exe" makes a single arg, but should be two args. You get the command taskkill /F "/IM testApp.exe". The proper invocation is

QStringList args;
args << "/F";
args << "/IM";
args << "testApp.exe";
QProcess::execute("taskkill", args);

Upvotes: 3

Related Questions