The QT program on the windows side often needs to open external programs (such as: Prog.exe), and it needs to be determined that the external program is only open.
1, judge whether there is prog.exe in the system
void Judge ()
{
Qprocess tasklist;
Tasklist.execute ("Tasklist", Qstringlist () << "-fi" << "imagename eq prog.exe");
}
2. Terminating the Prog.exe process in the system
void Kill ()
{
Qprocess Taskkill;
Taskkill.execute ("Taskkill", Qstringlist () << "-im" << "Prog.exe" << "-f");
}
3. Open External Program Prog.exe
void Open ()
{
Qprocess Newprog;
Newprog.start ("Prog.exe", Qstringlist () << "command");
}
Pan Wai 1:
Qprocess::execute ():----Open an external program in a blocking manner, and continue executing the current program only after the external program has finished executing. The standard output and standard errors of external programs are the standard output and standard errors that are redirected to the current program.
Qprocess::start ():----Open external programs as child processes, external processes and current processes do not interfere with each other, but the parent process of the external process is the current process.
Qprocess::startdetached ():----Open external programs in a separate way, the external process and the current process do not interfere with each other, the parent process of the external process is the INIT process of the system.
Pan Wai 2:
1. Tasklist-fi "imagename eq prog.exe"--Displays process information for the process named Prog.exe
2. Tasklist-fi "imagename ne prog.exe"--show process information that the process name is not Prog.exe
3. Tasklist-fi "PID eq 1111"--show process information of process number 1111
4. Taskkill-f-pid 1111--forcing the process to terminate process number 1111
5. Taskkill-f-im Prog.exe--forces the process tree to terminate for all processes named Prog.exe
6. Taskkill-f-fi "imagename eq prog.exe"--forces the process tree to terminate all processes named Prog.exe
http://blog.csdn.net/zuijinhaoma8/article/details/42061243
QT judgment and open process (Windows side)