7#include "ProgramLauncher.h"
13#include <QLocalServer>
14#include <QLocalSocket>
17#include "Application.h"
19#include "IException.h"
21#include "Preference.h"
40 FileName isisExecutableFileName(
"$ISISROOT/bin/" + program.
name());
41 bool isIsisProgram =
false;
45 program = isisExecutableFileName;
48 PvlGroup &dataDir = Preference::Preferences().findGroup(
"DataDirectory");
49 QString tempDir = dataDir[
"Temporary"];
51 QString command = program.
expanded() +
" " + parameters +
53 QStringList split = QProcess::splitCommand(command);
54 QString app = split.takeFirst();
58 QString msg =
"Program [" + programName +
"] does not appear to be a "
67 server.listen(serverName);
69 QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
70 env.insert(
"TEMPORARY", tempDir);
72 QProcess childProcess;
73 childProcess.setProcessEnvironment(env);
74 childProcess.setProcessChannelMode(QProcess::ForwardedChannels);
75 childProcess.start(app, paramList);
76 childProcess.waitForStarted();
78 bool connected =
false;
80 while(!connected && childProcess.state() != QProcess::NotRunning) {
83 connected = server.waitForNewConnection(30000);
84 childProcess.waitForFinished(100);
88 QString msg =
"Isis child process failed to communicate with parent";
92 QLocalSocket *childSocket = server.nextPendingConnection();
96 while(childSocket->state() != QLocalSocket::UnconnectedState) {
97 bool insideCode =
true;
98 bool messageDone =
false;
104 if(childSocket->waitForReadyRead(1000)) {
105 lineData = childSocket->read(childSocket->bytesAvailable());
107 for(
int i = 0; i < lineData.size(); i++) {
109 if(lineData[i] != (
char)27) {
117 if(lineData[i] != (
char)27) {
118 message += lineData[i];
138 childProcess.waitForFinished();
140 if(childProcess.exitCode() != 0) {
141 QString msg =
"Running Isis program [" + programName +
"] failed with "
142 "return status [" +
toString(childProcess.exitCode()) +
"]";
162 if(code ==
"PROGRESSTEXT" && iApp) {
163 iApp->UpdateProgress(msg,
true);
165 else if(code ==
"PROGRESS" && iApp) {
166 iApp->UpdateProgress(
toInt(msg),
true);
168 else if(code ==
"LOG" && iApp) {
169 stringstream msgStream;
174 if(logPvl.
groups() == 1 &&
177 iApp->Log(logPvl.
group(0));
180 else if(code ==
"GUILOG" && iApp) {
183 else if(code ==
"ERROR") {
184 stringstream msgStream;
187 msgStream >> errorPvl;
189 for(
int i = 0; i < errorPvl.
groups(); i++) {
191 QString emsg = g[
"Message"];
192 int ecode = g[
"Code"];
193 QString efile = g[
"File"];
194 int eline = g[
"Line"];
217 int status = system(fullCommand.toLatin1().data());
220 QString msg =
"Executing command [" + fullCommand +
221 "] failed with return status [" +
toString(status) +
"]";
static QString UserName()
Returns the user name.
File name manipulation and expansion.
bool fileExists() const
Returns true if the file exists; false otherwise.
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
ErrorType
Contains a set of exception error types.
@ Unknown
A type of error that cannot be classified as any of the other error types.
@ Programmer
This error is for when a programmer made an API call that was illegal.
void append(const IException &exceptionSource)
Appends the given exception (and its list of previous exceptions) to this exception's causational exc...
static void RunIsisProgram(QString isisProgramName, QString arguments)
Executes the Isis program with the given arguments.
static void RunSystemCommand(QString commandLine)
This runs arbitrary system commands.
static IException ProcessIsisMessageFromChild(QString code, QString msg)
This interprets a message sent along the pipe from a child process to us (the parent).
int keywords() const
Returns the number of keywords contained in the PvlContainer.
Contains multiple PvlContainers.
Container for cube-like labels.
PvlGroup & group(const int index)
Return the group at the specified index.
int groups() const
Returns the number of groups contained.
int objects() const
Returns the number of objects.
This is free and unencumbered software released into the public domain.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
int toInt(const QString &string)
Global function to convert from a string to an integer.
Namespace for the standard library.