QProcess 直接執行Program files(x86)目錄下的bat腳本失敗,wait

用QProcess執行一個服務的重啓腳本,重啓服務;發現Program files(x86),QProcess識別不了目錄

後來採用了替代的方法,用cmd.exe傳bat腳本路徑去執行;

void AlgorithmConfig::SlotRestartService()
{
    if (m_iHmsNum + m_iDfrNum + m_iGaitNum > m_iTotalNum)
    {
        QMessageBox::warning(NULL, "提示", "芯片分配數量大於總數量,請重新分配!");
        return;
    }
    m_strConfPath = QCoreApplication::applicationDirPath() + "/aianaservice/config.ini";//
    QProcess* process = new QProcess();
    process->setWorkingDirectory(QCoreApplication::applicationDirPath());
    QString commed = QCoreApplication::applicationDirPath() + "/aianaservice/restart.bat";//
    commed=commed.replace("/", "\\");
    QFileInfo info(commed);
    if (!info.exists())
    {
        QMessageBox::warning(NULL, "提示", "重啓服務腳本不存在:"+ commed);
        return;
    }
    process->start("cmd.exe", QStringList()<<  "/c" << QString("%1").arg(commed));
    //process->start(commed);//Program files(x86)路徑下執行失敗,waitforfinished返回false;
    bool started=process->waitForStarted();
    started=process->waitForFinished(-1);
    delete process;
    if (started)
    {
        QMessageBox::information(NULL, "提示", "重啓成功!請等待3分鐘,等服務器重新啓動!");
    }
    else
    {
        QMessageBox::warning(NULL, "提示", "重啓失敗");
    }
    
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章