Back to index

texmacs  1.0.7.15
qt_sys_utils.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : qt_sys_utils.cpp
00004 * DESCRIPTION: external command launcher
00005 * COPYRIGHT  : (C) 2009  David MICHEL
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #include "qt_sys_utils.hpp"
00013 #include "basic.hpp"
00014 #include "string.hpp"
00015 
00016 #include <QProcess>
00017 #include <QString>
00018 
00019 int
00020 qt_system (string cmd) {
00021   string result;
00022   return qt_system (cmd, result);
00023 }
00024 
00025 int
00026 qt_system (string cmd, string& result) {
00027   QProcess proc;
00028 
00029   proc.setProcessChannelMode (QProcess::MergedChannels);
00030   char* _cmd = as_charp (cmd);
00031 #if defined (__MINGW__) || defined (__MINGW32__)
00032   QString qcmd = QString::fromLocal8Bit (as_charp (_cmd));
00033 #else
00034   QString qcmd = "sh -c \"";
00035   qcmd += _cmd;
00036   qcmd += "\"";
00037 #endif
00038   tm_delete_array (_cmd);
00039   proc.start (qcmd);
00040   if (! proc.waitForStarted ()) {
00041     if (DEBUG_STD) cerr << "TeXmacs] System: failed to launch command\n";
00042     return 1;
00043   }
00044   proc.closeWriteChannel ();
00045   if (! proc.waitForFinished (-1)) {
00046     if (DEBUG_STD) cerr << "TeXmacs] System: waiting for too long\n";
00047     return 1;
00048   }
00049   result = proc.readAll ().constData ();
00050   if (DEBUG_STD) cerr << result;
00051   return proc.exitCode ();
00052 }
00053