Implementation of 'system' based on Qt
[texmacs.git] / src / src / Plugins / Qt / qt_sys_utils.cpp
blob784c7e03e97e32f38ee5a9aca3a3dc7c51c94a3e
2 /******************************************************************************
3 * MODULE : qt_system.cpp
4 * DESCRIPTION: external command launcher
5 * COPYRIGHT : (C) 2009 David MICHEL
6 *******************************************************************************
7 * This software falls under the GNU general public license version 3 or later.
8 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
9 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
10 ******************************************************************************/
12 #include "qt_sys_utils.hpp"
13 #include "basic.hpp"
14 #include "string.hpp"
16 #include <QProcess>
17 #include <QString>
19 int
20 qt_system (string cmd, string& result) {
21 QProcess proc;
23 proc.setProcessChannelMode (QProcess::MergedChannels);
24 char* _cmd = as_charp (cmd);
25 #if defined (__MINGW__) || defined (__MINGW32__)
26 QString qcmd = "CMD /S /C ";
27 qcmd += _cmd;
28 #else
29 QString qcmd = "sh -c \"";
30 qcmd += _cmd;
31 qcmd += "\"";
32 #endif
33 tm_delete_array (_cmd);
34 proc.start (qcmd);
35 if (! proc.waitForStarted ()) {
36 if (DEBUG_STD) cerr << "TeXmacs] System: failed to launch command\n";
37 return 1;
39 proc.closeWriteChannel ();
40 if (! proc.waitForFinished ()) {
41 if (DEBUG_STD) cerr << "TeXmacs] System: waiting for too long\n";
42 return 1;
44 result = proc.readAll ().constData ();
45 if (DEBUG_STD) cerr << result;
46 return proc.exitCode ();