Browse Source

Improve logging of running external program

PR #18901.
adaptive-webui-19844
Vladimir Golovnev 2 years ago committed by GitHub
parent
commit
758ea7edca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 29
      src/app/application.cpp

29
src/app/application.cpp

@ -563,6 +563,7 @@ void Application::runExternalProgram(const QString &programTemplate, const BitTo @@ -563,6 +563,7 @@ void Application::runExternalProgram(const QString &programTemplate, const BitTo
};
const QString logMsg = tr("Running external program. Torrent: \"%1\". Command: `%2`");
const QString logMsgError = tr("Failed to run external program. Torrent: \"%1\". Command: `%2`");
// The processing sequenece is different for Windows and other OS, this is intentional
#if defined(Q_OS_WIN)
@ -582,8 +583,6 @@ void Application::runExternalProgram(const QString &programTemplate, const BitTo @@ -582,8 +583,6 @@ void Application::runExternalProgram(const QString &programTemplate, const BitTo
for (int i = 1; i < argCount; ++i)
argList += QString::fromWCharArray(args[i]);
LogMsg(logMsg.arg(torrent->name(), program));
QProcess proc;
proc.setProgram(QString::fromWCharArray(args[0]));
proc.setArguments(argList);
@ -608,7 +607,11 @@ void Application::runExternalProgram(const QString &programTemplate, const BitTo @@ -608,7 +607,11 @@ void Application::runExternalProgram(const QString &programTemplate, const BitTo
args->startupInfo->hStdOutput = nullptr;
args->startupInfo->hStdError = nullptr;
});
proc.startDetached();
if (proc.startDetached())
LogMsg(logMsg.arg(torrent->name(), program));
else
LogMsg(logMsgError.arg(torrent->name(), program));
#else // Q_OS_WIN
QStringList args = Utils::String::splitCommand(programTemplate);
@ -624,11 +627,21 @@ void Application::runExternalProgram(const QString &programTemplate, const BitTo @@ -624,11 +627,21 @@ void Application::runExternalProgram(const QString &programTemplate, const BitTo
arg = replaceVariables(arg);
}
// show intended command in log
LogMsg(logMsg.arg(torrent->name(), replaceVariables(programTemplate)));
const QString command = args.takeFirst();
QProcess::startDetached(command, args);
QProcess proc;
proc.setProgram(command);
proc.setArguments(args);
if (proc.startDetached())
{
// show intended command in log
LogMsg(logMsg.arg(torrent->name(), replaceVariables(programTemplate)));
}
else
{
// show intended command in log
LogMsg(logMsgError.arg(torrent->name(), replaceVariables(programTemplate)));
}
#endif
}
@ -783,7 +796,7 @@ try @@ -783,7 +796,7 @@ try
actionExit->setIcon(UIThemeManager::instance()->getIcon(u"application-exit"_qs));
actionExit->setMenuRole(QAction::QuitRole);
actionExit->setShortcut(Qt::CTRL | Qt::Key_Q);
connect(actionExit, &QAction::triggered, this, [this]()
connect(actionExit, &QAction::triggered, this, []
{
QApplication::exit();
});

Loading…
Cancel
Save