Qt 调用CMD 并返回结果(隐藏窗口)

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();
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值