我正在运行包含以下内容的Windows批处理文件:
@echo off
:loop
taskkill /im "app.exe" /fi "STATUS eq NOT RESPONDING" /f >nul && start "" "C:\Program Files\app\app.exe"
goto loop
这将在我的应用程序没有响应时启动它。我使用QT应用程序运行此批处理文件,代码如下:
QProcess *process= new QProcess(this);
process->start("cmd.exe", QStringList() << "/c"<<"C:/Users/test.bat");
我在Qt应用程序的process->kill()
事件中使用close
终止了该过程。但是该过程没有关闭,它会不断运行批处理文件。还有其他方法可以正常杀死这个过程吗?
ApplicationWindow::ApplicationWindow( QWidget* inParent ) :
QMainWindow( inParent ),
ui( new Ui::ApplicationWindow )
{
process= new QProcess(this);
process->start("cmd.exe", QStringList() << "/c"<<"C:/Users/test.bat");
//bat file will monitor this application, when it's not responding, it starts again
}
void ApplicationWindow::closeEvent( QCloseEvent * inCloseEvent )
{
process->kill(); // if it killed the batch file, it starts app again
}