0

I'm calling Powershell from QProcess

    QProcess p;

    p.start("powershell.exe", QStringList() << "get-wmiobject win32_networkadapter -filter 'netconnectionstatus = 2' | select netconnectionid");

    if (p.waitForFinished())
        while(p.canReadLine())
        {
            auto line = QString::fromStdString(p.readLine().toStdString());
            qDebug() << line;
        }

From that, on QtCreator output, I see

"\r\n"
"\r\n"
"netconnectionid : Ethernet\r\n"
"\r\n"
"netconnectionid : VirtualBox Host-Only Network\r\n"
"\r\n"
"\r\n"
"\r\n"

I would like to reduce Powershell output to

"Ethernet"
"VirtualBox Host-Only Network"

How to format Powershell output to a minimum?

KcFnMi
  • 5,516
  • 10
  • 62
  • 136
  • 2
    no, don't call powershell just to read wmi info. You can just call the Windows wmi API directly and read the [`Win32_NetworkAdapter` class](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-networkadapter): [How to obtain data from WMI using a C Application?](https://stackoverflow.com/q/1431103/995714), [Example: Getting WMI Data from the Local Computer](https://learn.microsoft.com/en-us/windows/win32/wmisdk/example--getting-wmi-data-from-the-local-computer), https://stackoverflow.com/a/60589780/995714 – phuclv Jun 21 '22 at 03:24
  • Really appreciate this comment. However for simple things `QProcess/Powershell` way might be better, don't you think? – KcFnMi Jun 21 '22 at 04:48

0 Answers0