]> git.sven.stormbind.net Git - sven/vym.git/blob - src/vymprocess.cpp
New upstream version 2.9.22
[sven/vym.git] / src / vymprocess.cpp
1 #include "vymprocess.h"
2 #include <cstdlib>
3
4 #include <QDebug>
5 #include <QMessageBox>
6
7 extern bool debug;
8
9 /////////////////////////////////////////////////////////////////
10 // Process
11 /////////////////////////////////////////////////////////////////
12 VymProcess::VymProcess()
13 {
14     connect(this, SIGNAL(readyReadStandardError()), this,
15             SLOT(readProcErrout()));
16     connect(this, SIGNAL(readyReadStandardOutput()), this,
17             SLOT(readProcStdout()));
18     clear();
19 }
20
21 VymProcess::~VymProcess() {}
22
23 void VymProcess::clear()
24 {
25     errOut = "";
26     stdOut = "";
27 }
28
29 void VymProcess::runScript(QString spath, QString fpath)
30 {
31     spath.replace("%f", fpath);
32     QStringList args = spath.split(' ');
33     spath = args.takeFirst();
34
35     if (debug)
36         qDebug() << "Process::runScript : " + spath + " " + args.join(" ");
37
38     start(spath, args);
39     if (!waitForStarted()) {
40         QMessageBox::critical(0, tr("Critical Error"),
41                               tr("Could not start %1").arg(spath));
42     }
43     else {
44         if (!waitForFinished())
45             QMessageBox::critical(0, tr("Critical Error"),
46                                   tr("%1 didn't exit normally").arg(spath) +
47                                       getErrout());
48         //      else
49         //          if (exitStatus()>0) showOutput=true;
50     }
51     /* TODO output for Process::runScript
52     qDebug()<<readAllStandardOutput();
53     qDebug()<<getStdout();
54     qDebug()<<getErrout();
55     addOutput ("\n");
56     addOutput (getErrout());
57     addOutput (getStdout());
58     */
59 }
60
61 void VymProcess::readProcErrout() { errOut += readAllStandardError(); }
62
63 void VymProcess::readProcStdout() { stdOut += readAllStandardOutput(); }
64
65 QString VymProcess::getErrout() { return errOut; }
66
67 QString VymProcess::getStdout() { return stdOut; }