void Ocr() { QString currentPath = QDir::currentPath(); currentPath = currentPath + "/image_grab/ocr.bmp"; string strCmd = "tesseract " + currentPath.toStdString() + " stdout"; qDebug() << currentPath; char buf[10240] = { 0 }; FILE* pf = NULL; AllocConsole();//新建窗口 ShowWindow(GetConsoleWindow(), SW_HIDE);//隐藏 if ((pf = _popen(strCmd.c_str(), "r")) == NULL) { return; } string strResult; while (fgets(buf, sizeof buf, pf)) { strResult += buf; } _pclose(pf); unsigned int iSize = strResult.size(); if (iSize > 0 && strResult[iSize - 1] == '\n') // linux { strResult = strResult.substr(0, iSize - 1); } QString result = QString(QString::fromLocal8Bit(strResult.c_str())); QStringList resList; resList = result.split("\n"); result = resList.join(" "); QMessageBox::information(this, "Ocr result", result); /// 以管理员的身份运行程序并返回结果 /// runas //string cmd = string("runas /noprofile /user:mymachine\\administrator \"cmd /c ") + "cmd /c chcp 65001 && ping www.baidu.com -n 1 -w 1000" + "\""; //strRe = getCmdResult(cmd); //qDebug() << strRe.c_str(); }