Read standard output and error upon completion. And properly close the channels before killing the process.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29628 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2009-05-11 11:51:52 +00:00
parent 3e3179b4d4
commit 54aefd360c

View File

@ -19,6 +19,7 @@
#include "support/os.h" #include "support/os.h"
#include <cstdlib> #include <cstdlib>
#include <iostream>
#include <QProcess> #include <QProcess>
@ -29,6 +30,15 @@ using namespace std;
namespace lyx { namespace lyx {
namespace support { namespace support {
static void killProcess(QProcess * p)
{
p->closeReadChannel(QProcess::StandardOutput);
p->closeReadChannel(QProcess::StandardError);
p->close();
delete p;
}
// Reuse of instance // Reuse of instance
int Systemcall::startscript(Starttype how, string const & what) int Systemcall::startscript(Starttype how, string const & what)
{ {
@ -50,6 +60,8 @@ int Systemcall::startscript(Starttype how, string const & what)
#else #else
QString cmd = QString::fromLocal8Bit(what.c_str()); QString cmd = QString::fromLocal8Bit(what.c_str());
QProcess * process = new QProcess; QProcess * process = new QProcess;
cmd.replace("python", "python2.5");
cmd.prepend("/usr/bin/");
process->start(cmd); process->start(cmd);
if (!process->waitForStarted(1000)) { if (!process->waitForStarted(1000)) {
LYXERR0("Qprocess " << cmd << " did not start!"); LYXERR0("Qprocess " << cmd << " did not start!");
@ -76,7 +88,9 @@ int Systemcall::startscript(Starttype how, string const & what)
LYXERR0("state " << process->state()); LYXERR0("state " << process->state());
LYXERR0("status " << process->exitStatus()); LYXERR0("status " << process->exitStatus());
} }
delete process; cout << fromqstr(QString::fromLocal8Bit(process->readAllStandardOutput().data())) << endl;
cerr << fromqstr(QString::fromLocal8Bit(process->readAllStandardError().data())) << endl;
killProcess(process);
return exit_code; return exit_code;
#endif #endif
} }