0

I need to parse the output of vol command only to get the id i.e only abcd-1234, that is being used in QProcess. Here is my code to get the Volume Serial Number:

QProcess process;
process.start("cmd /c vol C:");
process.waitForFinished(-1);
QByteArray out = process.readAllStandardOutput();
qDebug() << out;

Help me, thanks...

highlander141
  • 1,683
  • 3
  • 23
  • 48

1 Answers1

1

You can use the regular expression with QRegExp (http://qt-project.org/doc/qt-4.8/qregexp.html) to find the ID. The vol command will always return the same message. So, you can read the result line by line and search the matching line:

QRegExp rx( "The Volume Serial Number is (.+)\\."); // Match the line with the ID and store it.
if ( rx.exactMatch( line ) {
    QString id = rx.capturedTexts(1); // The first elt is the entire matching text.
    qDebug() << id;
}
Dimitry Ernot
  • 6,256
  • 2
  • 25
  • 37