]> git.lyx.org Git - features.git/blob - src/support/Systemcall.cpp
Reorganize the code a bit and Disable QProcess evaluation for now as nothing works...
[features.git] / src / support / Systemcall.cpp
1 /**
2  * \file Systemcall.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Asger Alstrup
7  *
8  * Interface cleaned up by
9  * \author Angus Leeming
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #include <config.h>
15
16 #include "support/debug.h"
17 #include "support/qstring_helpers.h"
18 #include "support/Systemcall.h"
19 #include "support/os.h"
20
21 #include <cstdlib>
22
23 #include <QProcess>
24
25 #define DISABLE_EVALUATE_QPROCESS
26
27 using namespace std;
28
29 namespace lyx {
30 namespace support {
31
32 // Reuse of instance
33 int Systemcall::startscript(Starttype how, string const & what)
34 {
35 #ifdef DISABLE_EVALUATE_QPROCESS
36         string command = what;
37
38         if (how == DontWait) {
39                 switch (os::shell()) {
40                 case os::UNIX:
41                         command += " &";
42                         break;
43                 case os::CMD_EXE:
44                         command = "start /min " + command;
45                         break;
46                 }
47         }
48
49         return ::system(command.c_str());
50 #else
51         QString cmd = QString::fromLocal8Bit(what.c_str());
52         QProcess * process = new QProcess;
53         process->start(cmd);
54         if (!process->waitForStarted(1000)) {
55                 LYXERR0("Qprocess " << cmd << " did not start!");
56                 LYXERR0("error " << process->error());
57                 LYXERR0("state " << process->state());
58                 LYXERR0("status " << process->exitStatus());
59                 return 10;
60         }
61         if (how == DontWait)
62                 return 0;
63
64         if (!process->waitForFinished(30000)) {
65                 LYXERR0("Qprocess " << cmd << " did not finished!");
66                 LYXERR0("error " << process->error());
67                 LYXERR0("state " << process->state());
68                 LYXERR0("status " << process->exitStatus());
69                 return 20;
70         }
71         int const exit_code = process->exitCode();
72         if (exit_code) {
73                 LYXERR0("Qprocess " << cmd << " finished!");
74                 LYXERR0("exitCode " << process->exitCode());
75                 LYXERR0("error " << process->error());
76                 LYXERR0("state " << process->state());
77                 LYXERR0("status " << process->exitStatus());
78         }
79         delete process;
80         return exit_code;
81 #endif
82 }
83
84 } // namespace support
85 } // namespace lyx