mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Fix output to terminal when LyX is launched from a GUI on *nix
aka Surrender to Windowsisms aka Resistance is futile, you will be assimilated git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34918 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
2467a88cde
commit
952a31a43e
@ -246,24 +246,14 @@ SystemcallPrivate::SystemcallPrivate(const std::string& of) :
|
||||
out_index_(0),
|
||||
err_index_(0),
|
||||
out_file_(of),
|
||||
use_stdout_(false),
|
||||
use_stderr_(false),
|
||||
process_events_(false)
|
||||
{
|
||||
if (!out_file_.empty()) {
|
||||
// Don't output to terminal if stdout is redirected
|
||||
use_stdout_ = false;
|
||||
// Check whether we have to simply throw away the output.
|
||||
if (out_file_ != os::nulldev())
|
||||
process_->setStandardOutputFile(toqstr(out_file_));
|
||||
} else {
|
||||
// Output to terminal if stdout exists and is not redirected
|
||||
use_stdout_ = os::is_terminal(os::STDOUT);
|
||||
}
|
||||
|
||||
// When there is a stderr use it
|
||||
use_stderr_ = os::is_terminal(os::STDERR);
|
||||
|
||||
connect(process_, SIGNAL(readyReadStandardOutput()), SLOT(stdOut()));
|
||||
connect(process_, SIGNAL(readyReadStandardError()), SLOT(stdErr()));
|
||||
connect(process_, SIGNAL(error(QProcess::ProcessError)), SLOT(processError(QProcess::ProcessError)));
|
||||
@ -335,20 +325,16 @@ bool SystemcallPrivate::waitWhile(State waitwhile, bool process_events, int time
|
||||
|
||||
SystemcallPrivate::~SystemcallPrivate()
|
||||
{
|
||||
flush();
|
||||
|
||||
if (out_index_) {
|
||||
out_data_[out_index_] = '\0';
|
||||
out_index_ = 0;
|
||||
if (use_stdout_)
|
||||
cout << out_data_;
|
||||
cout << out_data_;
|
||||
}
|
||||
cout.flush();
|
||||
if (err_index_) {
|
||||
err_data_[err_index_] = '\0';
|
||||
err_index_ = 0;
|
||||
if (use_stderr_)
|
||||
cerr << err_data_;
|
||||
cerr << err_data_;
|
||||
}
|
||||
cerr.flush();
|
||||
|
||||
@ -356,26 +342,6 @@ SystemcallPrivate::~SystemcallPrivate()
|
||||
}
|
||||
|
||||
|
||||
void SystemcallPrivate::flush()
|
||||
{
|
||||
if (process_) {
|
||||
// If the output has been redirected, we write it all at once.
|
||||
// Even if we are not running in a terminal, the output could go
|
||||
// to some log file, for example ~/.xsession-errors on *nix.
|
||||
|
||||
QString data = QString::fromLocal8Bit(process_->readAllStandardOutput().data());
|
||||
ProgressInterface::instance()->appendMessage(data);
|
||||
if (!use_stdout_ && out_file_.empty())
|
||||
cout << fromqstr(data);
|
||||
|
||||
data = QString::fromLocal8Bit(process_->readAllStandardError().data());
|
||||
ProgressInterface::instance()->appendError(data);
|
||||
if (!use_stderr_)
|
||||
cerr << fromqstr(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SystemcallPrivate::stdOut()
|
||||
{
|
||||
if (process_) {
|
||||
@ -383,12 +349,11 @@ void SystemcallPrivate::stdOut()
|
||||
process_->setReadChannel(QProcess::StandardOutput);
|
||||
while (process_->getChar(&c)) {
|
||||
out_data_[out_index_++] = c;
|
||||
if (c == '\n' || out_index_ + 1 == max_buffer_size_) {
|
||||
if (c == '\n' || out_index_ + 1 == buffer_size_) {
|
||||
out_data_[out_index_] = '\0';
|
||||
out_index_ = 0;
|
||||
ProgressInterface::instance()->appendMessage(QString::fromLocal8Bit(out_data_));
|
||||
if (use_stdout_)
|
||||
cout << out_data_;
|
||||
cout << out_data_;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -402,12 +367,11 @@ void SystemcallPrivate::stdErr()
|
||||
process_->setReadChannel(QProcess::StandardError);
|
||||
while (process_->getChar(&c)) {
|
||||
err_data_[err_index_++] = c;
|
||||
if (c == '\n' || err_index_ + 1 == max_buffer_size_) {
|
||||
if (c == '\n' || err_index_ + 1 == buffer_size_) {
|
||||
err_data_[err_index_] = '\0';
|
||||
err_index_ = 0;
|
||||
ProgressInterface::instance()->appendError(QString::fromLocal8Bit(err_data_));
|
||||
if (use_stderr_)
|
||||
cerr << err_data_;
|
||||
cerr << err_data_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,8 +51,6 @@ public:
|
||||
QString errorMessage() const;
|
||||
QString exitStatusMessage() const;
|
||||
|
||||
void flush();
|
||||
|
||||
QProcess* releaseProcess();
|
||||
|
||||
static void killProcess(QProcess * p);
|
||||
@ -78,14 +76,11 @@ private:
|
||||
std::string out_file_;
|
||||
|
||||
/// Size of buffers.
|
||||
static size_t const max_buffer_size_ = 200;
|
||||
static size_t const buffer_size_ = 200;
|
||||
/// Standard output buffer.
|
||||
char out_data_[max_buffer_size_];
|
||||
char out_data_[buffer_size_];
|
||||
/// Standard error buffer.
|
||||
char err_data_[max_buffer_size_];
|
||||
|
||||
bool use_stderr_;
|
||||
bool use_stdout_;
|
||||
char err_data_[buffer_size_];
|
||||
|
||||
QString cmd_;
|
||||
bool process_events_;
|
||||
|
@ -55,9 +55,6 @@ void remove_internal_args(int i, int num);
|
||||
/// Returns the name of the NULL device (/dev/null, null).
|
||||
std::string const & nulldev();
|
||||
|
||||
/// Tells whether \p channel is connected to a terminal or not.
|
||||
bool is_terminal(io_channel channel);
|
||||
|
||||
/// Returns "/" on *nix, "C:/", etc on Windows.
|
||||
std::string current_root();
|
||||
|
||||
|
@ -375,12 +375,6 @@ string const & nulldev()
|
||||
}
|
||||
|
||||
|
||||
bool is_terminal(io_channel channel)
|
||||
{
|
||||
return isatty(channel);
|
||||
}
|
||||
|
||||
|
||||
shell_type shell()
|
||||
{
|
||||
return UNIX;
|
||||
|
@ -206,12 +206,6 @@ string const & nulldev()
|
||||
}
|
||||
|
||||
|
||||
bool is_terminal(io_channel channel)
|
||||
{
|
||||
return isatty(channel);
|
||||
}
|
||||
|
||||
|
||||
shell_type shell()
|
||||
{
|
||||
return UNIX;
|
||||
|
@ -417,26 +417,6 @@ string const & nulldev()
|
||||
}
|
||||
|
||||
|
||||
bool is_terminal(io_channel channel)
|
||||
{
|
||||
switch (channel) {
|
||||
case STDIN:
|
||||
if (GetStdHandle(STD_INPUT_HANDLE) == NULL)
|
||||
return false;
|
||||
break;
|
||||
case STDOUT:
|
||||
if (GetStdHandle(STD_OUTPUT_HANDLE) == NULL)
|
||||
return false;
|
||||
break;
|
||||
case STDERR:
|
||||
if (GetStdHandle(STD_ERROR_HANDLE) == NULL)
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
shell_type shell()
|
||||
{
|
||||
return CMD_EXE;
|
||||
|
Loading…
Reference in New Issue
Block a user