WMIC command is working on cmd but not in QProcess
-
wrote on 6 Jan 2020, 19:18 last edited by
i wrote this code to get out:
QProcess p; p.setReadChannel(QProcess::StandardOutput); p.setReadChannelMode(QProcess::MergedChannels); p.start("wmic diskdrive where deviceid='\\\\.\\PHYSICALDRIVE0' get serialnumber,model,size"); p.waitForReadyRead(); qDebug()<<QString(p.readAllStandardOutput()).simplified().split(QRegExp("[\n\r ]"),QString::SkipEmptyParts); p.close();
when i run my qt app, i get this error :
("Node", "-", "Hostname", "ERROR", ":", "Description", "=", "Request", "no", "valid")
instead of:
Model SerialNumber Size ST9500***AS ******** 500105249280
-
i wrote this code to get out:
QProcess p; p.setReadChannel(QProcess::StandardOutput); p.setReadChannelMode(QProcess::MergedChannels); p.start("wmic diskdrive where deviceid='\\\\.\\PHYSICALDRIVE0' get serialnumber,model,size"); p.waitForReadyRead(); qDebug()<<QString(p.readAllStandardOutput()).simplified().split(QRegExp("[\n\r ]"),QString::SkipEmptyParts); p.close();
when i run my qt app, i get this error :
("Node", "-", "Hostname", "ERROR", ":", "Description", "=", "Request", "no", "valid")
instead of:
Model SerialNumber Size ST9500***AS ******** 500105249280
wrote on 6 Jan 2020, 19:44 last edited by JonB 1 Jun 2020, 19:55@Lemat said in WMIC command is working on cmd but not in QProcess:
My hunch is that there is an issue in your command-line where you have
deviceid='\\\\.\\PHYSICALDRIVE0'
. For example, I see example from https://superuser.com/a/647711/479430 where usingwmic DiskDrive where "DeviceID='\\\\.\\PHYSICALDRIVE<disk_index>'" Assoc /assocclass:Win32_DiskDriveToDiskPartition
while yours will generate
wmic diskdrive where deviceid='\\.\PHYSICALDRIVE0' get serialnumber,model,size
They differ in the
"
marks and the number of\
s. Start from the exact command you need to type into Windows shell (or from documentation) and adapt it to C++/argument forQProcess
from there.@KroMignon's may work, but it will be passing
deviceid='\\.\PHYSICALDRIVE0'
, is that what is intended?If your issue is over the backslash count, you might find you want to use C++ raw string literal here, e.g.
R"(deviceid='\\\\.\\PHYSICALDRIVE0')"
or whatever you decide the final command needs to look like backslash-wise. -
i wrote this code to get out:
QProcess p; p.setReadChannel(QProcess::StandardOutput); p.setReadChannelMode(QProcess::MergedChannels); p.start("wmic diskdrive where deviceid='\\\\.\\PHYSICALDRIVE0' get serialnumber,model,size"); p.waitForReadyRead(); qDebug()<<QString(p.readAllStandardOutput()).simplified().split(QRegExp("[\n\r ]"),QString::SkipEmptyParts); p.close();
when i run my qt app, i get this error :
("Node", "-", "Hostname", "ERROR", ":", "Description", "=", "Request", "no", "valid")
instead of:
Model SerialNumber Size ST9500***AS ******** 500105249280
wrote on 6 Jan 2020, 19:30 last edited by@Lemat I think you should change the function call to use an argument list to avoid space issues:
QProcess p; p.setReadChannel(QProcess::StandardOutput); p.setReadChannelMode(QProcess::MergedChannels); QStringList opt; opt << "diskdrive" << "where" << "deviceid='\\\\.\\PHYSICALDRIVE0'" << "get" << "serialnumber,model,size" p.start("wmic", opt); p.waitForReadyRead(); qDebug()<<QString(p.readAllStandardOutput()).simplified().split(QRegExp("[\n\r ]"),QString::SkipEmptyParts); p.close();
-
i wrote this code to get out:
QProcess p; p.setReadChannel(QProcess::StandardOutput); p.setReadChannelMode(QProcess::MergedChannels); p.start("wmic diskdrive where deviceid='\\\\.\\PHYSICALDRIVE0' get serialnumber,model,size"); p.waitForReadyRead(); qDebug()<<QString(p.readAllStandardOutput()).simplified().split(QRegExp("[\n\r ]"),QString::SkipEmptyParts); p.close();
when i run my qt app, i get this error :
("Node", "-", "Hostname", "ERROR", ":", "Description", "=", "Request", "no", "valid")
instead of:
Model SerialNumber Size ST9500***AS ******** 500105249280
wrote on 6 Jan 2020, 19:44 last edited by JonB 1 Jun 2020, 19:55@Lemat said in WMIC command is working on cmd but not in QProcess:
My hunch is that there is an issue in your command-line where you have
deviceid='\\\\.\\PHYSICALDRIVE0'
. For example, I see example from https://superuser.com/a/647711/479430 where usingwmic DiskDrive where "DeviceID='\\\\.\\PHYSICALDRIVE<disk_index>'" Assoc /assocclass:Win32_DiskDriveToDiskPartition
while yours will generate
wmic diskdrive where deviceid='\\.\PHYSICALDRIVE0' get serialnumber,model,size
They differ in the
"
marks and the number of\
s. Start from the exact command you need to type into Windows shell (or from documentation) and adapt it to C++/argument forQProcess
from there.@KroMignon's may work, but it will be passing
deviceid='\\.\PHYSICALDRIVE0'
, is that what is intended?If your issue is over the backslash count, you might find you want to use C++ raw string literal here, e.g.
R"(deviceid='\\\\.\\PHYSICALDRIVE0')"
or whatever you decide the final command needs to look like backslash-wise. -
@Lemat I think you should change the function call to use an argument list to avoid space issues:
QProcess p; p.setReadChannel(QProcess::StandardOutput); p.setReadChannelMode(QProcess::MergedChannels); QStringList opt; opt << "diskdrive" << "where" << "deviceid='\\\\.\\PHYSICALDRIVE0'" << "get" << "serialnumber,model,size" p.start("wmic", opt); p.waitForReadyRead(); qDebug()<<QString(p.readAllStandardOutput()).simplified().split(QRegExp("[\n\r ]"),QString::SkipEmptyParts); p.close();
wrote on 6 Jan 2020, 22:23 last edited by@KroMignon thank for your reply. but it not work.
-
@KroMignon thank for your reply. but it not work.
wrote on 6 Jan 2020, 22:26 last edited by KroMignon 1 Jun 2020, 22:28@Lemat Hi, I see the problem, you need to escape the backslashes:
QProcess p; p.setReadChannel(QProcess::StandardOutput); p.setReadChannelMode(QProcess::MergedChannels); QStringList opt; opt << "diskdrive" << "where" << "deviceid='\\\\\\\\.\\\\PHYSICALDRIVE0'" << "get" << "serialnumber,model,size" p.start("wmic", opt); p.waitForFinished(); qDebug()<<QString(p.readAllStandardOutput()).simplified().split(QRegExp("[\n\r ]"),QString::SkipEmptyParts); p.close();
-
@Lemat said in WMIC command is working on cmd but not in QProcess:
My hunch is that there is an issue in your command-line where you have
deviceid='\\\\.\\PHYSICALDRIVE0'
. For example, I see example from https://superuser.com/a/647711/479430 where usingwmic DiskDrive where "DeviceID='\\\\.\\PHYSICALDRIVE<disk_index>'" Assoc /assocclass:Win32_DiskDriveToDiskPartition
while yours will generate
wmic diskdrive where deviceid='\\.\PHYSICALDRIVE0' get serialnumber,model,size
They differ in the
"
marks and the number of\
s. Start from the exact command you need to type into Windows shell (or from documentation) and adapt it to C++/argument forQProcess
from there.@KroMignon's may work, but it will be passing
deviceid='\\.\PHYSICALDRIVE0'
, is that what is intended?If your issue is over the backslash count, you might find you want to use C++ raw string literal here, e.g.
R"(deviceid='\\\\.\\PHYSICALDRIVE0')"
or whatever you decide the final command needs to look like backslash-wise. -
@Lemat Hi, I see the problem, you need to escape the backslashes:
QProcess p; p.setReadChannel(QProcess::StandardOutput); p.setReadChannelMode(QProcess::MergedChannels); QStringList opt; opt << "diskdrive" << "where" << "deviceid='\\\\\\\\.\\\\PHYSICALDRIVE0'" << "get" << "serialnumber,model,size" p.start("wmic", opt); p.waitForFinished(); qDebug()<<QString(p.readAllStandardOutput()).simplified().split(QRegExp("[\n\r ]"),QString::SkipEmptyParts); p.close();
wrote on 6 Jan 2020, 22:37 last edited by@KroMignon good answer again. thanks for you time!!!. very thanks!!!.
1/7