mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 19:25:39 +00:00
Avoid #ifdef's and use OS specific code.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29652 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
50ddeeb77e
commit
97303baac2
@ -60,12 +60,12 @@ int Systemcall::startscript(Starttype how, string const & what)
|
||||
#else
|
||||
QString cmd = QString::fromLocal8Bit(what.c_str());
|
||||
QProcess * process = new QProcess;
|
||||
#ifndef _WIN32
|
||||
if (isatty(1))
|
||||
process->setStandardOutputFile(toqstr("/dev/stdout"));
|
||||
if (isatty(2))
|
||||
process->setStandardErrorFile(toqstr("/dev/stderr"));
|
||||
#endif
|
||||
if (os::terminal_output()) {
|
||||
// Qt won't start the process if we redirect stdout and
|
||||
// stderr this way, without running in a terminal.
|
||||
process->setStandardOutputFile(toqstr(os::stdoutdev()));
|
||||
process->setStandardErrorFile(toqstr(os::stderrdev()));
|
||||
}
|
||||
process->start(cmd);
|
||||
if (!process->waitForStarted(3000)) {
|
||||
LYXERR0("Qprocess " << cmd << " did not start!");
|
||||
@ -92,10 +92,12 @@ int Systemcall::startscript(Starttype how, string const & what)
|
||||
LYXERR0("state " << process->state());
|
||||
LYXERR0("status " << process->exitStatus());
|
||||
}
|
||||
#ifdef _WIN32
|
||||
cout << fromqstr(QString::fromLocal8Bit(process->readAllStandardOutput().data())) << endl;
|
||||
cerr << fromqstr(QString::fromLocal8Bit(process->readAllStandardError().data())) << endl;
|
||||
#endif
|
||||
if (!os::terminal_output()) {
|
||||
// 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;
|
||||
}
|
||||
killProcess(process);
|
||||
return exit_code;
|
||||
#endif
|
||||
|
@ -33,6 +33,16 @@ void init(int argc, char * argv[]);
|
||||
/// Returns the name of the NULL device (/dev/null, null).
|
||||
std::string const & nulldev();
|
||||
|
||||
/// Returns the name of the stdout device (/dev/stdout, /dev/tty, conout$).
|
||||
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();
|
||||
|
||||
/// Returns "/" on *nix, "C:/", etc on Windows.
|
||||
std::string current_root();
|
||||
|
||||
|
@ -240,6 +240,26 @@ string const & nulldev()
|
||||
}
|
||||
|
||||
|
||||
string const & stdoutdev()
|
||||
{
|
||||
static string const stdoutdev_ = "/dev/stdout";
|
||||
return stdoutdev_;
|
||||
}
|
||||
|
||||
|
||||
string const & stderrdev()
|
||||
{
|
||||
static string const stderrdev_ = "/dev/stderr";
|
||||
return stderrdev_;
|
||||
}
|
||||
|
||||
|
||||
bool terminal_output()
|
||||
{
|
||||
return isatty(1) && isatty(2);
|
||||
}
|
||||
|
||||
|
||||
shell_type shell()
|
||||
{
|
||||
return UNIX;
|
||||
|
@ -30,8 +30,23 @@ namespace lyx {
|
||||
namespace support {
|
||||
namespace os {
|
||||
|
||||
namespace {
|
||||
|
||||
string stdoutdev_ = "/dev/stdout";
|
||||
string stderrdev_ = "/dev/stderr";
|
||||
|
||||
} // namespace anon
|
||||
|
||||
void init(int, char *[])
|
||||
{}
|
||||
{
|
||||
// Check whether /dev/stdout and /dev/stderr are available,
|
||||
// otherwise default to /dev/tty.
|
||||
if (access(stdoutdev_.c_str(), W_OK) != 0
|
||||
|| access(stderrdev_.c_str(), W_OK) != 0) {
|
||||
stdoutdev_ = "/dev/tty";
|
||||
stderrdev_ = "/dev/tty";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
string current_root()
|
||||
@ -130,6 +145,24 @@ string const & nulldev()
|
||||
}
|
||||
|
||||
|
||||
string const & stdoutdev()
|
||||
{
|
||||
return stdoutdev_;
|
||||
}
|
||||
|
||||
|
||||
string const & stderrdev()
|
||||
{
|
||||
return stderrdev_;
|
||||
}
|
||||
|
||||
|
||||
bool terminal_output()
|
||||
{
|
||||
return isatty(1) && isatty(2);
|
||||
}
|
||||
|
||||
|
||||
shell_type shell()
|
||||
{
|
||||
return UNIX;
|
||||
|
@ -296,6 +296,31 @@ string const & nulldev()
|
||||
}
|
||||
|
||||
|
||||
string const & stdoutdev()
|
||||
{
|
||||
static string const stdoutdev_ = "conout$";
|
||||
return stdoutdev_;
|
||||
}
|
||||
|
||||
|
||||
string const & stderrdev()
|
||||
{
|
||||
static string const stderrdev_ = "conout$";
|
||||
return stderrdev_;
|
||||
}
|
||||
|
||||
|
||||
bool terminal_output()
|
||||
{
|
||||
// FIXME: Passing conout$ to Qt fails, most probably for the
|
||||
// reason explained here:
|
||||
// http://support.microsoft.com/?scid=kb%3Ben-us%3B90088&x=15&y=15
|
||||
// How to convince Qt to open conout$ in FILE_SHARE_WRITE mode?
|
||||
// For the time being, we assume we are not running in a terminal.
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
shell_type shell()
|
||||
{
|
||||
return CMD_EXE;
|
||||
|
Loading…
Reference in New Issue
Block a user