Skip to content

Commit

Permalink
fix: Exec() always return Unkonw Error
Browse files Browse the repository at this point in the history
We should return the real error message from stderr.

Log:
  • Loading branch information
kamiyadm committed Jan 12, 2024
1 parent 08828ac commit 8f0c2da
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/linglong/util/runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8f0c2da

Please sign in to comment.