LogTailFiles: Replace QProcess with Process

Change-Id: Ia154daf16a801d8d09ac1a1a5e00c669ad9f36ad
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2023-07-13 13:30:34 +02:00
parent b5808cdd56
commit 301e18f12b

View File

@@ -65,27 +65,20 @@ public:
watcher.setFuture(promise.future()); watcher.setFuture(promise.future());
// Process to print the console output while app is running. // Process to print the console output while app is running.
auto logProcess = [&](QProcess *tailProcess, std::shared_ptr<QTemporaryFile> file) { auto logProcess = [&](Process *tailProcess, std::shared_ptr<QTemporaryFile> file) {
QObject::connect(tailProcess, &QProcess::readyReadStandardOutput, &loop, [&, tailProcess] { QObject::connect(tailProcess, &Process::readyReadStandardOutput, &loop, [&, tailProcess] {
if (!promise.isCanceled()) if (!promise.isCanceled())
emit logMessage(QString::fromLocal8Bit(tailProcess->readAll())); emit logMessage(QString::fromLocal8Bit(tailProcess->readAllRawStandardOutput()));
}); });
tailProcess->start(QStringLiteral("tail"), {"-f", file->fileName()}); tailProcess->setCommand({FilePath::fromString("tail"), {"-f", file->fileName()}});
tailProcess->start();
}; };
auto processDeleter = [](QProcess *process) { std::unique_ptr<Process> tailStdout(new Process);
if (process->state() != QProcess::NotRunning) {
process->terminate();
process->waitForFinished();
}
delete process;
};
std::unique_ptr<QProcess, void(*)(QProcess *)> tailStdout(new QProcess, processDeleter);
if (stdoutFile) if (stdoutFile)
logProcess(tailStdout.get(), stdoutFile); logProcess(tailStdout.get(), stdoutFile);
std::unique_ptr<QProcess, void(*)(QProcess *)> tailStderr(new QProcess, processDeleter); std::unique_ptr<Process> tailStderr(new Process);
if (stderrFile) if (stderrFile)
logProcess(tailStderr.get(), stderrFile); logProcess(tailStderr.get(), stderrFile);