| 175 | } |
| 176 | |
| 177 | bool CHook::RunCommand(const QString &program, const QStringList &args, int timeout) |
| 178 | { |
| 179 | QProcess process; |
| 180 | process.setProgram(program); |
| 181 | if(!args.isEmpty()) |
| 182 | process.setArguments(args); |
| 183 | |
| 184 | //qDebug(log) << "Command:" << program << args; |
| 185 | |
| 186 | process.start(); |
| 187 | |
| 188 | if (!process.waitForFinished(timeout)) { |
| 189 | qWarning(log) << "Command timeout:" << program << args; |
| 190 | return false; |
| 191 | } |
| 192 | |
| 193 | if (process.exitCode() != 0) { |
| 194 | QString errorOutput = process.readAllStandardError(); |
| 195 | qWarning(log) << "Command failed:" << program << args |
| 196 | << "exit code:" << process.exitCode() |
| 197 | << "failed:" << errorOutput; |
| 198 | return false; |
| 199 | } |
| 200 | |
| 201 | QString standardOutput = process.readAllStandardOutput(); |
| 202 | if (!standardOutput.isEmpty()) { |
| 203 | qDebug(log) << "Command output:" << standardOutput.trimmed(); |
| 204 | } |
| 205 | |
| 206 | return true; |
| 207 | } |