00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <qprocess.h>
00024 #include <qapplication.h>
00025 #include <qeventloop.h>
00026
00027 #include "klfblockprocess.h"
00028
00029 KLFBlockProcess::KLFBlockProcess(QObject *p) : QProcess(p)
00030 {
00031 #ifdef KLFBACKEND_QT4
00032 connect(this, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(ourProcExited()));
00033 #else
00034 connect(this, SIGNAL(wroteToStdin()), this, SLOT(ourProcGotOurStdinData()));
00035 connect(this, SIGNAL(processExited()), this, SLOT(ourProcExited()));
00036 #endif
00037 }
00038
00039
00040 KLFBlockProcess::~KLFBlockProcess()
00041 {
00042 }
00043
00044 void KLFBlockProcess::ourProcGotOurStdinData()
00045 {
00046 #ifndef KLFBACKEND_QT4
00047 closeStdin();
00048 #endif
00049 }
00050
00051 void KLFBlockProcess::ourProcExited()
00052 {
00053 _runstatus = 1;
00054 }
00055 #ifndef KLFBACKEND_QT4
00056 bool KLFBlockProcess::startProcess(QStringList cmd, QCString str, QStringList env)
00057 {
00058 return startProcess(cmd, QByteArray().duplicate(str.data(), str.length()), env);
00059 }
00060 #endif
00061 bool KLFBlockProcess::startProcess(QStringList cmd, QStringList env)
00062 {
00063 return startProcess(cmd, QByteArray(), env);
00064 }
00065
00066 bool KLFBlockProcess::startProcess(QStringList cmd, QByteArray stdindata, QStringList env)
00067 {
00068 _runstatus = 0;
00069
00070 #ifdef KLFBACKEND_QT4
00071 if (env.size() > 0)
00072 setEnvironment(env);
00073
00074 QString program = cmd.front();
00075 QStringList args = cmd;
00076 args.erase(args.begin());
00077 start(program, args);
00078 if ( ! waitForStarted() )
00079 return false;
00080
00081 write(stdindata.constData(), stdindata.size());
00082 closeWriteChannel();
00083 #else
00084 setArguments(cmd);
00085 QStringList *e = &env;
00086 if (e->size() == 0)
00087 e = 0;
00088
00089 if (! start(e) )
00090 return false;
00091
00092 writeToStdin(stdindata);
00093
00094 #endif
00095
00096 while (_runstatus == 0) {
00097 #ifdef KLFBACKEND_QT4
00098 qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
00099 #else
00100 qApp->eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
00101 #endif
00102 }
00103
00104 if (_runstatus < 0) {
00105 return false;
00106 }
00107
00108 return true;
00109 }