PDA

View Full Version : QProcess read nothing when It start wmic



rogerer
2nd July 2013, 09:54
I use wmic like the following code.But It start this cmd error,and return after call p.waitForStarted.

Does sb kown why?


QString cmdTask = "wmic.exe /OUTPUT:STDOUT process where name=\"startServer.exe\" get executablepath";
QStringList output = execute(cmdTask);




QStringList execute(const QString &cmd) {
QProcess p;
p.start(cmd);
if (!p.waitForStarted()) {
return QStringList();
}

if (!p.waitForFinished()) {
return QStringList();
}
int res = p.exitCode();
if (res) { //error
return QStringList();
}
QByteArray data = p.readAllStandardOutput()

QString ds = QString::fromLocal8Bit(data);

QStringList out = ds.split("\r\n");

return out;
}