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, "提示", "重启失败");
    }
    
}

 

posted @ 2023-03-07 18:09  一字千金  阅读(331)  评论(0编辑  收藏  举报