]> git.lyx.org Git - features.git/commitdiff
Allow to separately redirect stdout and stderr.
authorEnrico Forestieri <forenr@lyx.org>
Wed, 13 May 2009 12:55:01 +0000 (12:55 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Wed, 13 May 2009 12:55:01 +0000 (12:55 +0000)
Now "lyx > stdout.log" should produce the same output as before
the switch to QProcess.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29655 a592a061-630c-0410-9148-cb99ea01b6c8

src/support/Systemcall.cpp
src/support/os.h
src/support/os_cygwin.cpp
src/support/os_unix.cpp
src/support/os_win32.cpp

index f1db006a8e67209c1804ab7cf36d6ec908e33dfc..b7f0355fc654cba86df86e1c9e2e3ea0b7493e29 100644 (file)
@@ -60,12 +60,15 @@ int Systemcall::startscript(Starttype how, string const & what)
 #else
        QString cmd = QString::fromLocal8Bit(what.c_str());
        QProcess * process = new QProcess;
-       if (os::terminal_output()) {
-               // Qt won't start the process if we redirect stdout and
-               // stderr this way, without running in a terminal.
+
+       // Qt won't start the process if we redirect stdout/stderr in
+       // this way and they are not connected to a terminal (maybe
+       // because we were launched from some desktop GUI).
+       if (os::is_terminal(os::STDOUT))
                process->setStandardOutputFile(toqstr(os::stdoutdev()));
+       if (os::is_terminal(os::STDERR))
                process->setStandardErrorFile(toqstr(os::stderrdev()));
-       }
+
        process->start(cmd);
        if (!process->waitForStarted(3000)) {
                LYXERR0("Qprocess " << cmd << " did not start!");
@@ -92,13 +95,17 @@ int Systemcall::startscript(Starttype how, string const & what)
                LYXERR0("state " << process->state());
                LYXERR0("status " << process->exitStatus());
        }
-       if (!os::terminal_output()) {
-           // The output may have been redirected. But even if we are not
-           // running in a terminal, the output could go to some log file,
-           // for example ~/.xsession-errors on *nix.
-           cout << fromqstr(QString::fromLocal8Bit(process->readAllStandardOutput().data())) << endl;
-           cerr << fromqstr(QString::fromLocal8Bit(process->readAllStandardError().data())) << endl;
-       }
+
+       // 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.
+       if (!os::is_terminal(os::STDOUT))
+               cout << fromqstr(QString::fromLocal8Bit(
+                           process->readAllStandardOutput().data()));
+       if (!os::is_terminal(os::STDERR))
+               cerr << fromqstr(QString::fromLocal8Bit(
+                           process->readAllStandardError().data()));
+
        killProcess(process);
        return exit_code;
 #endif
index b5d1fecd80afc22b38c128702124a61dbcdef49f..1644ef4bf001eac42a13bae957aa28999736e720 100644 (file)
@@ -27,6 +27,12 @@ enum shell_type {
        CMD_EXE
 };
 
+enum io_channel {
+       STDIN = 0,
+       STDOUT,
+       STDERR
+};
+
 /// Do some work just once.
 void init(int argc, char * argv[]);
 
@@ -39,9 +45,8 @@ std::string const & stdoutdev();
 /// Returns the name of the stderr device (/dev/stderr, /dev/tty, conout$).
 std::string const & stderrdev();
 
-/// Tells whether LyX is being run from a terminal and stdout/stderr are
-/// not redirected.
-bool terminal_output();
+/// 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();
index 840a11ccc17e9df1d51614560887a25b0f2743e1..068d7035d685c373f10f16e92b8fd3442194bbc2 100644 (file)
@@ -254,9 +254,9 @@ string const & stderrdev()
 }
 
 
-bool terminal_output()
+bool is_terminal(io_channel channel)
 {
-       return isatty(1) && isatty(2);
+       return isatty(channel);
 }
 
 
index ccc04b69e2a26609573dedf8e3c790c7a16be0f4..a9ae59850cb37ecd4cc735d754572f49000fe706 100644 (file)
@@ -157,9 +157,9 @@ string const & stderrdev()
 }
 
 
-bool terminal_output()
+bool is_terminal(io_channel channel)
 {
-       return isatty(1) && isatty(2);
+       return isatty(channel);
 }
 
 
index f17f06de5f29b75cedd016e4e267ab10d63c496f..464d8df1114e0a20d80363aa47da4d22fc2ebf96 100644 (file)
@@ -310,7 +310,7 @@ string const & stderrdev()
 }
 
 
-bool terminal_output()
+bool is_terminal(io_channel channel)
 {
        // FIXME: Passing conout$ to Qt fails, most probably for the
        // reason explained here: