SHOW:
|
|
- or go back to the newest paste.
| 1 | #include "task.h" | |
| 2 | ||
| 3 | struct TaskResult | |
| 4 | {
| |
| 5 | int exitCode ; | |
| 6 | QByteArray output ; | |
| 7 | } | |
| 8 | ||
| 9 | TaskResult runTask( const QString& exe ) | |
| 10 | {
| |
| 11 | - | return Task::await( [ exe ](){
|
| 11 | + | return Task::await<TaskResult>( [ & ](){
|
| 12 | ||
| 13 | QProcess e ; | |
| 14 | e.start( exe ) ; | |
| 15 | e.waitForFinished( -1 ) ; | |
| 16 | ||
| 17 | TaskResult r ; | |
| 18 | r.exitCode = e.exitCode() ; | |
| 19 | r.output = r.readAllStandardOutput() ; | |
| 20 | ||
| 21 | return r ; | |
| 22 | } ) ; | |
| 23 | } | |
| 24 | ||
| 25 | QString ExtendedSysMon::getAllHdd() | |
| 26 | {
| |
| 27 | if (debug) qDebug() << "[DE]" << "[getAllHdd]"; | |
| 28 | ||
| 29 | QStringList devices; | |
| 30 | QString cmd = QString("find /dev -name [hms]d[a-z]");
| |
| 31 | QString qoutput = QString("");
| |
| 32 | if (debug) qDebug() << "[DE]" << "[getAllHdd]" << ":" << "Run cmd" << cmd; | |
| 33 | ||
| 34 | TaskResult r = runTask(cmd) ; | |
| 35 | ||
| 36 | if (debug) qDebug() << "[DE]" << "[getAllHdd]" << ":" << "Cmd returns" << r.exitCode; | |
| 37 | qoutput = QTextCodec::codecForMib(106)->toUnicode(r.readAllStandardOutput); | |
| 38 | for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++)
| |
| 39 | devices.append(qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i]);
| |
| 40 | if (debug) qDebug() << "[DE]" << "[getAllHdd]" << ":" << "Device list" << devices; | |
| 41 | ||
| 42 | return devices.join(QChar(','));
| |
| 43 | } |