Skip to content

Commit

Permalink
Ensure MantidPlot exits with 0 status code on script success.
Browse files Browse the repository at this point in the history
Refs #9559
  • Loading branch information
martyngigg committed Jun 2, 2014
1 parent b9c991e commit 334175b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
Expand Up @@ -16438,6 +16438,7 @@ void ApplicationWindow::executeScriptFile(const QString & filename, const Script
code += in.readLine() + "\n";
}
Script *runner = scriptingEnv()->newScript(filename, this, Script::NonInteractive);
connect(runner, SIGNAL(finished(const QString &)), this, SLOT(onScriptExecuteSuccess(const QString &)));
connect(runner, SIGNAL(error(const QString &, const QString &, int)), this, SLOT(onScriptExecuteError(const QString &, const QString &, int)));
runner->redirectStdOut(false);
scriptingEnv()->redirectStdOut(false);
Expand All @@ -16459,6 +16460,18 @@ void ApplicationWindow::executeScriptFile(const QString & filename, const Script
delete runner;
}

/**
* This is the slot for handing script exits when it returns successfully
*
* @param lineNumber The line number in the script that caused the error.
*/
void ApplicationWindow::onScriptExecuteSuccess(const QString & message)
{
g_log.notice() << message.toStdString() << "\n";
this->setExitCode(0);
this->exitWithPresetCode();
}

/**
* This is the slot for handing script execution errors. It is only
* attached by ::executeScriptFile which is only done in the '-xq'
Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/MantidPlot/src/ApplicationWindow.h
Expand Up @@ -230,6 +230,8 @@ public slots:
ApplicationWindow * loadScript(const QString& fn);
/// Runs a script from a file. Mainly useful for automatically running scripts
void executeScriptFile(const QString & filename, const Script::ExecutionMode execMode);
/// Slot to connect the script execution success
void onScriptExecuteSuccess(const QString & message);
/// Slot to connect the script execution errors to
void onScriptExecuteError(const QString & message, const QString & scriptName, int lineNumber);
/// Runs an arbitrary lump of python code, return true/false on success/failure.
Expand Down

0 comments on commit 334175b

Please sign in to comment.