7 #include "ProgramLauncher.h"
13 #include <QLocalServer>
14 #include <QLocalSocket>
17 #include "Application.h"
19 #include "IException.h"
37 void ProgramLauncher::RunIsisProgram(QString programName,
40 FileName isisExecutableFileName(
"$ISISROOT/bin/" + program.
name());
41 bool isIsisProgram =
false;
45 program = isisExecutableFileName;
48 QString command = program.
expanded() +
" " + parameters +
52 QString msg =
"Program [" + programName +
"] does not appear to be a "
54 throw IException(IException::Unknown, msg, _FILEINFO_);
57 QString serverName =
"isis_" + Application::UserName() +
61 server.listen(serverName);
63 QProcess childProcess;
64 childProcess.setProcessChannelMode(QProcess::ForwardedChannels);
65 childProcess.start(command);
66 childProcess.waitForStarted();
68 bool connected =
false;
70 while(!connected && childProcess.state() != QProcess::NotRunning) {
73 connected = server.waitForNewConnection(30000);
74 childProcess.waitForFinished(100);
78 QString msg =
"Isis child process failed to communicate with parent";
79 throw IException(IException::Programmer, msg, _FILEINFO_);
82 QLocalSocket *childSocket = server.nextPendingConnection();
86 while(childSocket->state() != QLocalSocket::UnconnectedState) {
87 bool insideCode =
true;
88 bool messageDone =
false;
94 if(childSocket->waitForReadyRead(1000)) {
95 lineData = childSocket->read(childSocket->bytesAvailable());
97 for(
int i = 0; i < lineData.size(); i++) {
99 if(lineData[i] != (
char)27) {
107 if(lineData[i] != (
char)27) {
108 message += lineData[i];
119 ProcessIsisMessageFromChild(code, message));
128 childProcess.waitForFinished();
130 if(childProcess.exitCode() != 0) {
131 QString msg =
"Running Isis program [" + programName +
"] failed with "
132 "return status [" +
toString(childProcess.exitCode()) +
"]";
133 throw IException(errors, IException::Unknown, msg, _FILEINFO_);
149 ProgramLauncher::ProcessIsisMessageFromChild(QString code, QString msg) {
152 if(code ==
"PROGRESSTEXT" && iApp) {
155 else if(code ==
"PROGRESS" && iApp) {
158 else if(code ==
"LOG" && iApp) {
159 stringstream msgStream;
164 if(logPvl.groups() == 1 &&
165 logPvl.keywords() == 0 &&
166 logPvl.objects() == 0) {
167 iApp->
Log(logPvl.group(0));
170 else if(code ==
"GUILOG" && iApp) {
173 else if(code ==
"ERROR") {
174 stringstream msgStream;
177 msgStream >> errorPvl;
179 for(
int i = 0; i < errorPvl.groups(); i++) {
181 QString eclass = g[
"Class"];
182 QString emsg = g[
"Message"];
183 int ecode = g[
"Code"];
184 QString efile = g[
"File"];
185 int eline = g[
"Line"];
207 void ProgramLauncher::RunSystemCommand(QString fullCommand) {
208 int status = system(fullCommand.toLatin1().data());
211 QString msg =
"Executing command [" + fullCommand +
212 "] failed with return status [" +
toString(status) +
"]";
213 throw IException(IException::Programmer, msg, _FILEINFO_);