| 197 | } |
| 198 | |
| 199 | bool CommandLineExporterPrivate::executeCommand |
| 200 | ( |
| 201 | const QString &command, |
| 202 | const QString &inputFilePath, |
| 203 | const QString &textInput, |
| 204 | const QString &outputFilePath, |
| 205 | const QString &options, |
| 206 | const bool smartTypographyEnabled, |
| 207 | QString &stdoutOutput, |
| 208 | QString &stderrOutput |
| 209 | ) const |
| 210 | { |
| 211 | QProcess process; |
| 212 | process.setReadChannel(QProcess::StandardOutput); |
| 213 | |
| 214 | QString expandedCommand = command + " "; |
| 215 | |
| 216 | if (!outputFilePath.isNull() && !outputFilePath.isEmpty()) { |
| 217 | // Redirect stdout to the output file path if the path variable wasn't |
| 218 | // set in the command string. |
| 219 | // |
| 220 | if (!expandedCommand.contains( |
| 221 | CommandLineExporter::OUTPUT_FILE_PATH_VAR)) { |
| 222 | process.setStandardOutputFile(outputFilePath); |
| 223 | } else { |
| 224 | // Surround file path with quotes in case there are spaces in the |
| 225 | // path. |
| 226 | // |
| 227 | QString outputFilePathWithQuotes = QString('\"') + |
| 228 | outputFilePath + '\"'; |
| 229 | expandedCommand.replace( |
| 230 | CommandLineExporter::OUTPUT_FILE_PATH_VAR, |
| 231 | outputFilePathWithQuotes); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | if (smartTypographyEnabled && !smartTypographyOnArgument.isNull()) { |
| 236 | expandedCommand.replace |
| 237 | ( |
| 238 | CommandLineExporter::SMART_TYPOGRAPHY_ARG, |
| 239 | smartTypographyOnArgument |
| 240 | ); |
| 241 | } else if (!smartTypographyEnabled |
| 242 | && !smartTypographyOffArgument.isNull()) { |
| 243 | expandedCommand.replace |
| 244 | ( |
| 245 | CommandLineExporter::SMART_TYPOGRAPHY_ARG, |
| 246 | smartTypographyOffArgument |
| 247 | ); |
| 248 | } else { |
| 249 | // Replace the smart typography argument with an empty string |
| 250 | // in case the above two cases are not applicable. |
| 251 | // |
| 252 | expandedCommand.replace |
| 253 | ( |
| 254 | CommandLineExporter::SMART_TYPOGRAPHY_ARG, |
| 255 | "" |
| 256 | ); |