参考1
主要有:
QProcess::execute("C:\\Environment\\influxDB_1_5_2\\influxd.exe")
QProcess proc; proc.start("C:\\Environment\\influxDB_1_5_2\\influxd.exe");
if (QProcess::startDetached("C:\\Environment\\influxDB_1_5_2\\influxd.exe")) qDebug() <<"Running..."; else qDebug() <<"Failed";
bool IsProcessExist(const QString &processName)// 返回 true/false { QProcess proc; proc.start("tasklist"); proc.waitForFinished();// 等待 tasklist 启动 QByteArray result = proc.readAllStandardOutput(); QString str = result; if(str.contains(processName)) { qDebug() << processName <<"is Running"; return true; } else { qDebug() << "Can't find " << processName; return false; } }
bool IsProcessExist(const QString &processName)// 返回 true/false { QString strInfo = QString::number(QProcess::execute("tasklist", QStringList()<<"-fi"<<"imagename eq influxd.exe")); if(strInfo .contains(processName)) { qDebug() << processName <<"is Running"; return true; } else { qDebug() << "Can't find " << processName; return false; } }
void getProcessInfo() // 返回信息(需要对返回信息进行判断) { QProcess::execute("tasklist", QStringList()<<"-fi"<<"imagename eq prog.exe"); }
// 通过进程ID结束进程(该进程由proc对象打开前提是通过 proc) QProcess::startDetached("taskkill -t -f /pid " + QString::number(proc.processId()));
// 通过进程名字结束进程 QProcess::startDetached("taskkill -t -f /IM " + QString("influxd.exe"));