diff --git a/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp b/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
index 2b4b38256c9c1b81cb08a6b83f85efe78ba02b92..071663e8c05a5af4e40ee230dddfcc53dc71915e 100644
--- a/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
+++ b/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
@@ -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);
@@ -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'
diff --git a/Code/Mantid/MantidPlot/src/ApplicationWindow.h b/Code/Mantid/MantidPlot/src/ApplicationWindow.h
index 4e1a157ec32f8b5b957009bd9ce2a92d9c690d80..c575f6fb3d60538d5f7e1ee6506b81bfc954a705 100644
--- a/Code/Mantid/MantidPlot/src/ApplicationWindow.h
+++ b/Code/Mantid/MantidPlot/src/ApplicationWindow.h
@@ -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.