通用工具方法
| 462 | |
| 463 | // 通用工具方法 |
| 464 | bool CDesktopShortcutManager::runCommand(const QString &program, const QStringList &args, int timeout) |
| 465 | { |
| 466 | QProcess process; |
| 467 | process.setProgram(program); |
| 468 | if(!args.isEmpty()) |
| 469 | process.setArguments(args); |
| 470 | |
| 471 | //qDebug(log) << "Command:" << program << args; |
| 472 | |
| 473 | process.start(); |
| 474 | |
| 475 | if (!process.waitForFinished(timeout)) { |
| 476 | qWarning(log) << "Command timeout:" << program << args; |
| 477 | return false; |
| 478 | } |
| 479 | |
| 480 | if (process.exitCode() != 0) { |
| 481 | QString errorOutput = process.readAllStandardError(); |
| 482 | qWarning(log) << "Command failed:" << program << args |
| 483 | << "exit code:" << process.exitCode() |
| 484 | << "failed:" << errorOutput; |
| 485 | return false; |
| 486 | } |
| 487 | |
| 488 | QString standardOutput = process.readAllStandardOutput(); |
| 489 | if (!standardOutput.isEmpty()) { |
| 490 | qDebug(log) << "Command output:" << standardOutput.trimmed(); |
| 491 | } |
| 492 | |
| 493 | return true; |
| 494 | } |
| 495 | |
| 496 | QString CDesktopShortcutManager::getCommandOutput(const QString &program, const QStringList &args) |
| 497 | { |