Fix stdin/stdout encoding on Windows. (#2425)
QTextStream uses the system default locale, but this breaks in various situations: (1) It does not work on the native Windows shell (cmd.exe, Powershell), since the default Windows locale is Windows-1252, but the shell uses Windows-850. (2) It also breaks on *nix systems where the locale is Latin1 or C, which is the case for most CI systems or build servers. We allow overriding the detected codec by setting the ENCODING_OVERRIDE environment variable, but otherwise prefer Windows-850 on Windows and UTF-8 on any other system, even if LANG is set to something else. This resolves #2413
This commit is contained in:
@@ -23,8 +23,8 @@
|
||||
#include "Clip.h"
|
||||
|
||||
#include <QCommandLineParser>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "cli/TextStream.h"
|
||||
#include "cli/Utils.h"
|
||||
#include "core/Database.h"
|
||||
#include "core/Entry.h"
|
||||
@@ -42,7 +42,7 @@ Clip::~Clip()
|
||||
|
||||
int Clip::execute(const QStringList& arguments)
|
||||
{
|
||||
QTextStream out(Utils::STDOUT);
|
||||
TextStream out(Utils::STDOUT);
|
||||
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription(description);
|
||||
@@ -73,7 +73,7 @@ int Clip::execute(const QStringList& arguments)
|
||||
|
||||
int Clip::clipEntry(Database* database, QString entryPath, QString timeout)
|
||||
{
|
||||
QTextStream err(Utils::STDERR);
|
||||
TextStream err(Utils::STDERR);
|
||||
|
||||
int timeoutSeconds = 0;
|
||||
if (!timeout.isEmpty() && !timeout.toInt()) {
|
||||
@@ -83,7 +83,7 @@ int Clip::clipEntry(Database* database, QString entryPath, QString timeout)
|
||||
timeoutSeconds = timeout.toInt();
|
||||
}
|
||||
|
||||
QTextStream outputTextStream(Utils::STDOUT, QIODevice::WriteOnly);
|
||||
TextStream outputTextStream(Utils::STDOUT, QIODevice::WriteOnly);
|
||||
Entry* entry = database->rootGroup()->findEntry(entryPath);
|
||||
if (!entry) {
|
||||
err << QObject::tr("Entry %1 not found.").arg(entryPath) << endl;
|
||||
|
||||
Reference in New Issue
Block a user