29 #include <QLocalServer>
30 #include <QLocalSocket>
53 void ProgramLauncher::RunIsisProgram(QString programName,
56 FileName isisExecutableFileName(
"$ISISROOT/bin/" + program.name());
57 bool isIsisProgram =
false;
59 if(isisExecutableFileName.fileExists()) {
61 program = isisExecutableFileName;
64 QString command = program.expanded() +
" " + parameters +
68 QString msg =
"Program [" + programName +
"] does not appear to be a "
69 "valid Isis 3 program";
73 QString serverName =
"isis_" + Application::UserName() +
77 server.listen(serverName);
79 QProcess childProcess;
80 childProcess.setProcessChannelMode(QProcess::ForwardedChannels);
81 childProcess.start(command);
82 childProcess.waitForStarted();
84 bool connected =
false;
86 while(!connected && childProcess.state() != QProcess::NotRunning) {
89 connected = server.waitForNewConnection(30000);
90 childProcess.waitForFinished(100);
94 QString msg =
"Isis child process failed to communicate with parent";
98 QLocalSocket *childSocket = server.nextPendingConnection();
102 while(childSocket->state() != QLocalSocket::UnconnectedState) {
103 bool insideCode =
true;
104 bool messageDone =
false;
110 if(childSocket->waitForReadyRead(1000)) {
111 lineData = childSocket->read(childSocket->bytesAvailable());
113 for(
int i = 0; i < lineData.size(); i++) {
115 if(lineData[i] != (
char)27) {
123 if(lineData[i] != (
char)27) {
124 message += lineData[i];
135 ProcessIsisMessageFromChild(code, message));
144 childProcess.waitForFinished();
146 if(childProcess.exitCode() != 0) {
147 QString msg =
"Running Isis program [" + programName +
"] failed with "
148 "return status [" +
toString(childProcess.exitCode()) +
"]";
165 ProgramLauncher::ProcessIsisMessageFromChild(QString code, QString msg) {
168 if(code ==
"PROGRESSTEXT" && iApp) {
171 else if(code ==
"PROGRESS" && iApp) {
174 else if(code ==
"LOG" && iApp) {
175 stringstream msgStream;
180 if(logPvl.groups() == 1 &&
181 logPvl.keywords() == 0 &&
182 logPvl.objects() == 0) {
183 iApp->
Log(logPvl.group(0));
186 else if(code ==
"GUILOG" && iApp) {
189 else if(code ==
"ERROR") {
190 stringstream msgStream;
193 msgStream >> errorPvl;
195 for(
int i = 0; i < errorPvl.groups(); i++) {
197 QString eclass = g[
"Class"];
198 QString emsg = g[
"Message"];
199 int ecode = g[
"Code"];
200 QString efile = g[
"File"];
201 int eline = g[
"Line"];
223 void ProgramLauncher::RunSystemCommand(QString fullCommand) {
224 int status = system(fullCommand.toAscii().data());
227 QString msg =
"Executing command [" + fullCommand +
228 "] failed with return status [" +
toString(status) +
"]";