3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
8 * Interface cleaned up by
9 * \author Angus Leeming
11 * Full author contact details are available in file CREDITS.
16 #include "support/debug.h"
17 #include "support/qstring_helpers.h"
18 #include "support/Systemcall.h"
19 #include "support/os.h"
33 static void killProcess(QProcess * p)
35 p->closeReadChannel(QProcess::StandardOutput);
36 p->closeReadChannel(QProcess::StandardError);
43 int Systemcall::startscript(Starttype how, string const & what)
46 string command = what;
48 if (how == DontWait) {
49 switch (os::shell()) {
54 command = "start /min " + command;
59 return ::system(command.c_str());
61 QString cmd = QString::fromLocal8Bit(what.c_str());
62 QProcess * process = new QProcess;
63 if (os::terminal_output()) {
64 // Qt won't start the process if we redirect stdout and
65 // stderr this way, without running in a terminal.
66 process->setStandardOutputFile(toqstr(os::stdoutdev()));
67 process->setStandardErrorFile(toqstr(os::stderrdev()));
70 if (!process->waitForStarted(3000)) {
71 LYXERR0("Qprocess " << cmd << " did not start!");
72 LYXERR0("error " << process->error());
73 LYXERR0("state " << process->state());
74 LYXERR0("status " << process->exitStatus());
80 if (!process->waitForFinished(180000)) {
81 LYXERR0("Qprocess " << cmd << " did not finished!");
82 LYXERR0("error " << process->error());
83 LYXERR0("state " << process->state());
84 LYXERR0("status " << process->exitStatus());
87 int const exit_code = process->exitCode();
89 LYXERR0("Qprocess " << cmd << " finished!");
90 LYXERR0("exitCode " << process->exitCode());
91 LYXERR0("error " << process->error());
92 LYXERR0("state " << process->state());
93 LYXERR0("status " << process->exitStatus());
95 if (!os::terminal_output()) {
96 // Even if we are not running in a terminal, the output could
97 // go to some log file, for example ~/.xsession-errors on *nix.
98 cout << fromqstr(QString::fromLocal8Bit(process->readAllStandardOutput().data())) << endl;
99 cerr << fromqstr(QString::fromLocal8Bit(process->readAllStandardError().data())) << endl;
101 killProcess(process);
106 } // namespace support