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