From 8f0c2daab466101f5460d9d7d9f2e2687ed6978e Mon Sep 17 00:00:00 2001 From: kamiyadm Date: Fri, 12 Jan 2024 09:56:39 +0800 Subject: [PATCH] fix: Exec() always return Unkonw Error We should return the real error message from stderr. Log: --- src/linglong/util/runner.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/linglong/util/runner.h b/src/linglong/util/runner.h index 9a2f2cb0c..d425b20ae 100644 --- a/src/linglong/util/runner.h +++ b/src/linglong/util/runner.h @@ -32,24 +32,25 @@ inline Error Exec(const QString &program, QProcess process; process.setProgram(program); process.setArguments(args); + QString standardError; - QProcess::connect(&process, &QProcess::readyReadStandardOutput, [&]() { - if (standardOutput) { - standardOutput->append(process.readAllStandardOutput()); - } else { - qDebug() << QString::fromLocal8Bit(process.readAllStandardOutput()).trimmed(); - } - }); + QProcess::connect(&process, &QProcess::readyReadStandardOutput, [&]() { + if (standardOutput) { + standardOutput->append(process.readAllStandardOutput().trimmed()); + } else { + qDebug() << QString::fromLocal8Bit(process.readAllStandardOutput()).trimmed(); + } + }); QProcess::connect(&process, &QProcess::readyReadStandardError, [&]() { - qDebug() << QString::fromLocal8Bit(process.readAllStandardError()).trimmed(); + standardError.append(process.readAllStandardError().trimmed()); }); process.start(); process.waitForStarted(timeout); process.waitForFinished(timeout); - return NewError(process.exitCode(), process.errorString()); + return NewError(process.exitCode(), standardError); } } // namespace util