From 952a31a43ef55e86f11dfe58842ccc588a5a47c5 Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Fri, 16 Jul 2010 14:30:46 +0000 Subject: [PATCH] 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 --- src/support/Systemcall.cpp | 48 +++++---------------------------- src/support/SystemcallPrivate.h | 11 +++----- src/support/os.h | 3 --- src/support/os_cygwin.cpp | 6 ----- src/support/os_unix.cpp | 6 ----- src/support/os_win32.cpp | 20 -------------- 6 files changed, 9 insertions(+), 85 deletions(-) diff --git a/src/support/Systemcall.cpp b/src/support/Systemcall.cpp index 5fec0b8f03..dda23d66bc 100644 --- a/src/support/Systemcall.cpp +++ b/src/support/Systemcall.cpp @@ -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_; } } } diff --git a/src/support/SystemcallPrivate.h b/src/support/SystemcallPrivate.h index c446358647..c8e3aa734c 100644 --- a/src/support/SystemcallPrivate.h +++ b/src/support/SystemcallPrivate.h @@ -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_; diff --git a/src/support/os.h b/src/support/os.h index 36209a2647..08ad8206c9 100644 --- a/src/support/os.h +++ b/src/support/os.h @@ -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(); diff --git a/src/support/os_cygwin.cpp b/src/support/os_cygwin.cpp index 31416c0f71..ad97c38bc2 100644 --- a/src/support/os_cygwin.cpp +++ b/src/support/os_cygwin.cpp @@ -375,12 +375,6 @@ string const & nulldev() } -bool is_terminal(io_channel channel) -{ - return isatty(channel); -} - - shell_type shell() { return UNIX; diff --git a/src/support/os_unix.cpp b/src/support/os_unix.cpp index 139743b43a..337f728d5c 100644 --- a/src/support/os_unix.cpp +++ b/src/support/os_unix.cpp @@ -206,12 +206,6 @@ string const & nulldev() } -bool is_terminal(io_channel channel) -{ - return isatty(channel); -} - - shell_type shell() { return UNIX; diff --git a/src/support/os_win32.cpp b/src/support/os_win32.cpp index d0bf73ffb3..dd5f0e594d 100644 --- a/src/support/os_win32.cpp +++ b/src/support/os_win32.cpp @@ -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; -- 2.39.2