]> git.lyx.org Git - features.git/commitdiff
no output to stdout when redirecting, cleanup
authorPeter Kümmel <syntheticpp@gmx.net>
Fri, 16 Jul 2010 09:57:46 +0000 (09:57 +0000)
committerPeter Kümmel <syntheticpp@gmx.net>
Fri, 16 Jul 2010 09:57:46 +0000 (09:57 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34915 a592a061-630c-0410-9148-cb99ea01b6c8

src/support/Systemcall.cpp
src/support/SystemcallPrivate.h

index ab1ef6029906b70a904524ab6ce8bf3505edefd7..5fec0b8f039fa630d7b6e50dd298fb64d67b81a1 100644 (file)
@@ -246,16 +246,24 @@ SystemcallPrivate::SystemcallPrivate(const std::string& of) :
                                 out_index_(0),
                                 err_index_(0),
                                 out_file_(of), 
-                                terminal_out_exists_(os::is_terminal(os::STDOUT)),
-                                terminal_err_exists_(os::is_terminal(os::STDERR)),
+                                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)));
@@ -332,14 +340,14 @@ SystemcallPrivate::~SystemcallPrivate()
        if (out_index_) {
                out_data_[out_index_] = '\0';
                out_index_ = 0;
-               if (terminal_out_exists_)
+               if (use_stdout_)
                        cout << out_data_;
        }
        cout.flush();
        if (err_index_) {
                err_data_[err_index_] = '\0';
                err_index_ = 0;
-               if (terminal_err_exists_)
+               if (use_stderr_)
                        cerr << err_data_;
        }
        cerr.flush();
@@ -357,12 +365,12 @@ void SystemcallPrivate::flush()
                
                QString data = QString::fromLocal8Bit(process_->readAllStandardOutput().data());
                ProgressInterface::instance()->appendMessage(data);
-               if (!terminal_out_exists_ && out_file_.empty())
+               if (!use_stdout_ && out_file_.empty())
                        cout << fromqstr(data);
                
                data = QString::fromLocal8Bit(process_->readAllStandardError().data());
                ProgressInterface::instance()->appendError(data);
-               if (!terminal_err_exists_)
+               if (!use_stderr_)
                        cerr << fromqstr(data);
        }
 }
@@ -379,7 +387,7 @@ void SystemcallPrivate::stdOut()
                                out_data_[out_index_] = '\0';
                                out_index_ = 0;
                                ProgressInterface::instance()->appendMessage(QString::fromLocal8Bit(out_data_));
-                               if (terminal_out_exists_)
+                               if (use_stdout_)
                                        cout << out_data_;
                        }
                }
@@ -398,7 +406,7 @@ void SystemcallPrivate::stdErr()
                                err_data_[err_index_] = '\0';
                                err_index_ = 0;
                                ProgressInterface::instance()->appendError(QString::fromLocal8Bit(err_data_));
-                               if (terminal_err_exists_)
+                               if (use_stderr_)
                                        cerr << err_data_;
                        }
                }
index 958fae1e704af5b39fbdbab509eb93df29e2b210..c446358647ea50a9f033d0562db6e32529fbc50c 100644 (file)
@@ -84,8 +84,8 @@ private:
        /// Standard error buffer.
        char err_data_[max_buffer_size_];
 
-       bool terminal_err_exists_;
-       bool terminal_out_exists_;
+       bool use_stderr_;
+       bool use_stdout_;
 
        QString cmd_;
        bool process_events_;