7#include "ProgramLauncher.h"
13#include <QLocalServer>
14#include <QLocalSocket>
17#include "Application.h"
19#include "IException.h"
39 FileName isisExecutableFileName(
"$ISISROOT/bin/" + program.name());
40 bool isIsisProgram =
false;
42 if(isisExecutableFileName.fileExists()) {
44 program = isisExecutableFileName;
47 QString command = program.expanded() +
" " + parameters +
51 QString msg =
"Program [" + programName +
"] does not appear to be a "
60 server.listen(serverName);
62 QProcess childProcess;
63 childProcess.setProcessChannelMode(QProcess::ForwardedChannels);
64 childProcess.start(command);
65 childProcess.waitForStarted();
67 bool connected =
false;
69 while(!connected && childProcess.state() != QProcess::NotRunning) {
72 connected = server.waitForNewConnection(30000);
73 childProcess.waitForFinished(100);
77 QString msg =
"Isis child process failed to communicate with parent";
81 QLocalSocket *childSocket = server.nextPendingConnection();
85 while(childSocket->state() != QLocalSocket::UnconnectedState) {
86 bool insideCode =
true;
87 bool messageDone =
false;
93 if(childSocket->waitForReadyRead(1000)) {
94 lineData = childSocket->read(childSocket->bytesAvailable());
96 for(
int i = 0; i < lineData.size(); i++) {
98 if(lineData[i] != (
char)27) {
106 if(lineData[i] != (
char)27) {
107 message += lineData[i];
127 childProcess.waitForFinished();
129 if(childProcess.exitCode() != 0) {
130 QString msg =
"Running Isis program [" + programName +
"] failed with "
131 "return status [" +
toString(childProcess.exitCode()) +
"]";
151 if(code ==
"PROGRESSTEXT" && iApp) {
154 else if(code ==
"PROGRESS" && iApp) {
157 else if(code ==
"LOG" && iApp) {
158 stringstream msgStream;
163 if(logPvl.groups() == 1 &&
164 logPvl.keywords() == 0 &&
165 logPvl.objects() == 0) {
166 iApp->
Log(logPvl.group(0));
169 else if(code ==
"GUILOG" && iApp) {
172 else if(code ==
"ERROR") {
173 stringstream msgStream;
176 msgStream >> errorPvl;
178 for(
int i = 0; i < errorPvl.groups(); i++) {
180 QString emsg = g[
"Message"];
181 int ecode = g[
"Code"];
182 QString efile = g[
"File"];
183 int eline = g[
"Line"];
206 int status = system(fullCommand.toLatin1().data());
209 QString msg =
"Executing command [" + fullCommand +
210 "] failed with return status [" +
toString(status) +
"]";
static void Log(PvlGroup &results)
Writes Pvl results to sessionlog and printfile.
static void GuiLog(const Pvl &results)
Writes the Pvl results to the sessionlog, but not to the printfile.
void UpdateProgress(const QString &text, bool print)
Updates the progress bar in the gui.
static QString UserName()
Returns the user name.
File name manipulation and expansion.
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).
Contains multiple PvlContainers.
Container for cube-like labels.
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.