运行Windows批处理文件时,QProcess不会退出

时间:2016-12-30 08:45:25

标签: c++ windows qt visual-c++

我正在运行包含以下内容的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终止了该过程。但是该过程没有关闭,它会不断运行批处理文件。还有其他方法可以正常杀死这个过程吗?

app_window.cpp

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
}

0 个答案:

没有答案