]> git.lyx.org Git - features.git/blob - src/support/Systemcall.cpp
22b042448f7b1cf3dc9f68522f0348327cf727f2
[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 using namespace std;
26
27 namespace lyx {
28 namespace support {
29
30 // Reuse of instance
31 int Systemcall::startscript(Starttype how, string const & what)
32 {
33         string command = what;
34
35         if (how == DontWait) {
36                 switch (os::shell()) {
37                 case os::UNIX:
38                         command += " &";
39                         break;
40                 case os::CMD_EXE:
41                         command = "start /min " + command;
42                         break;
43                 }
44         }
45
46 //#define DISABLE_EVALUATE_QPROCESS
47 #ifndef DISABLE_EVALUATE_QPROCESS
48         QString cmd = QString::fromLocal8Bit(command.c_str());
49         QProcess process;
50         process.start(cmd);
51         if (!process.waitForStarted(1000)) {
52                 LYXERR0("Qprocess " << cmd << " did not start!");
53                 LYXERR0("error " << process.error());
54                 LYXERR0("state " << process.state());
55                 LYXERR0("status " << process.exitStatus());
56                 return 10;
57         }
58         if (!process.waitForFinished(30000)) {
59                 LYXERR0("Qprocess " << cmd << " did not finished!");
60                 LYXERR0("error " << process.error());
61                 LYXERR0("state " << process.state());
62                 LYXERR0("status " << process.exitStatus());
63                 return 20;
64         }
65         if (process.exitCode()) {
66                 LYXERR0("Qprocess " << cmd << " finished!");
67                 LYXERR0("exitCode " << process.exitCode());
68                 LYXERR0("error " << process.error());
69                 LYXERR0("state " << process.state());
70                 LYXERR0("status " << process.exitStatus());
71         }
72         return process.exitCode();
73 #endif
74
75         return ::system(command.c_str());
76 }
77
78 } // namespace support
79 } // namespace lyx