From bae58f8ddf2a12532d90c392efaeca68ed9d72fd Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 2 Apr 2024 19:38:44 +0800 Subject: [PATCH] fix: merge output of stdout and stderr --- RedPandaIDE/mainwindow.cpp | 9 ++++++--- RedPandaIDE/utils.cpp | 8 +++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index ec529019..171bc95f 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -1247,9 +1247,12 @@ void MainWindow::executeTool(PToolItem item) QTemporaryFile file(QDir::tempPath()+QDir::separator()+"XXXXXX.bat"); file.setAutoRemove(false); if (file.open()) { - file.write(escapeCommandForPlatformShell( - "cd", {"/d", localizePath(workDir)} - ).toLocal8Bit() + LINE_BREAKER); + QString localizedDir=localizePath(workDir); + if (!localizedDir.isEmpty()) { + file.write(escapeCommandForPlatformShell( + "cd", {"/d", localizedDir} + ).toLocal8Bit() + LINE_BREAKER); + } file.write(escapeCommandForPlatformShell(program, params).toLocal8Bit() + LINE_BREAKER); file.close(); diff --git a/RedPandaIDE/utils.cpp b/RedPandaIDE/utils.cpp index 81641e0a..bf459a28 100644 --- a/RedPandaIDE/utils.cpp +++ b/RedPandaIDE/utils.cpp @@ -367,11 +367,9 @@ QByteArray runAndGetOutput(const QString &cmd, const QString& workingDir, const } else { process.setProcessEnvironment(env); } + process.setProcessChannelMode(QProcess::MergedChannels); + process.setReadChannel(QProcess::StandardOutput); process.setWorkingDirectory(workingDir); - process.connect(&process,&QProcess::readyReadStandardError, - [&](){ - result.append(process.readAllStandardError()); - }); process.connect(&process,&QProcess::readyReadStandardOutput, [&](){ result.append(process.readAllStandardOutput()); @@ -387,7 +385,7 @@ QByteArray runAndGetOutput(const QString &cmd, const QString& workingDir, const process.closeWriteChannel(); process.waitForFinished(); if (errorOccurred) { - result += process.errorString().toUtf8(); + result += process.errorString().toLocal8Bit(); } return result; }