QProcess: The system cannot find the file specificed even when full path is provided

Here is my full code:

#include <QCoreApplication>

#include "iostream"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QProcess process;
    QString path = "C:\\Windows\\System32\\wbem\\WMIC.exe";
    QString arg  = "cpu get name";
    QStringList arguments; arguments << arg;

    //process.start(path,arguments);
    process.start(path + " " + arg);

    //qDebug() << "Started";
    std::cout << "Started" << std::endl;
    if (!process.waitForFinished()){
        qDebug() << "ERROR" << process.errorString();
    }
    else {
        qDebug() << "Printing output";
        qDebug().noquote() << process.readAllStandardOutput();
    }
    qDebug() << "Finished";

    return 0;
    //return a.exec();
}

I’m tryting to get some hardware specs (liek the model of the GPU Card, or in this case, the CPU) from a Windows machine. I’ve read that the wmic command with the right parameters can get me this. But after severla attempts I’m left with these two non working options:

If arguments is filled with "cpu get name" I get an empty string as a result.

If arguments are nto provided I get the error in the title. Which I assume it means that the QProcess class cannot find the specified file. I don’t know how that is possible as literally added the entire path.

Any help would be appreciated.

Also I’ve read that this might be do to compiler reasons and just in case I’m compiling a 64 bit application with MSVC2019.

>Solution :

Use QStringList arguments = arg.split(" "); and then process.start(path,arguments);.

Leave a Reply