fix: merge output of stdout and stderr

This commit is contained in:
Roy Qu 2024-04-02 19:38:44 +08:00
parent bf245a7842
commit bae58f8ddf
2 changed files with 9 additions and 8 deletions

View File

@ -1247,9 +1247,12 @@ void MainWindow::executeTool(PToolItem item)
QTemporaryFile file(QDir::tempPath()+QDir::separator()+"XXXXXX.bat");
file.setAutoRemove(false);
if (file.open()) {
QString localizedDir=localizePath(workDir);
if (!localizedDir.isEmpty()) {
file.write(escapeCommandForPlatformShell(
"cd", {"/d", localizePath(workDir)}
"cd", {"/d", localizedDir}
).toLocal8Bit() + LINE_BREAKER);
}
file.write(escapeCommandForPlatformShell(program, params).toLocal8Bit()
+ LINE_BREAKER);
file.close();

View File

@ -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;
}