| 108 | } |
| 109 | |
| 110 | bool KDevFormatFile::executeCommand(QString command) |
| 111 | { |
| 112 | if (command.isEmpty()) { |
| 113 | qStdOut() << ", empty command => nothing to do\n"; |
| 114 | return true; |
| 115 | } |
| 116 | qStdOut() << ", using command \"" << command << "\"\n"; |
| 117 | |
| 118 | command.replace(QLatin1String("$ORIGFILE"), m_origFilePath); |
| 119 | command.replace(QLatin1String("$TMPFILE"), m_tempFilePath); |
| 120 | |
| 121 | #ifdef Q_OS_WIN |
| 122 | const QString interpreter = QStringLiteral("cmd"); |
| 123 | const QStringList arguments{QStringLiteral("/c"), command}; |
| 124 | #else |
| 125 | const QString interpreter = QStringLiteral("sh"); |
| 126 | const QStringList arguments{QStringLiteral("-c"), command}; |
| 127 | #endif |
| 128 | const int execResult = QProcess::execute(interpreter, arguments); |
| 129 | |
| 130 | if (execResult != 0) { |
| 131 | const QString interpreterDescription = QLatin1String("interpreter ") + interpreter; |
| 132 | if (execResult == -2) { |
| 133 | qStdOut() << "error: " << interpreterDescription << " failed to start\n"; |
| 134 | return false; |
| 135 | } |
| 136 | if (execResult == -1) { |
| 137 | qStdOut() << "error: " << interpreterDescription << " crashed\n"; |
| 138 | return false; |
| 139 | } |
| 140 | qStdOut() << "warning: " << interpreterDescription << " exited with code " << execResult << '\n'; |
| 141 | } |
| 142 | |
| 143 | return true; |
| 144 | } |
| 145 | |
| 146 | } |