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