Index: /trunk/FACT++/src/LocalControl.h
===================================================================
--- /trunk/FACT++/src/LocalControl.h	(revision 13896)
+++ /trunk/FACT++/src/LocalControl.h	(revision 13897)
@@ -121,13 +121,20 @@
 
             const int target = stoi(str.substr(3));
-            while (fStateMachine->GetCurrentState()!=target && timeout>Time())
+            while (fStateMachine->GetCurrentState()!=target && timeout>Time() && !T::IsScriptStopped())
                 usleep(1);
 
-            if (fStateMachine->GetCurrentState()!=target)
+            if (fStateMachine->GetCurrentState()==target)
+                return true;
+
+            int label = -1;
+            in >> label;
+            if (in.fail() && !in.eof())
             {
-                int label = -1;
-                in >> label;
-                T::SetLabel(label);
+                lout << kRed << "Invalid label in '" << str.substr(3) << "'" << endl;
+                T::StopScript();
+                return true;
             }
+            T::SetLabel(label);
+
             return true;
         }
Index: /trunk/FACT++/src/Readline.cc
===================================================================
--- /trunk/FACT++/src/Readline.cc	(revision 13896)
+++ /trunk/FACT++/src/Readline.cc	(revision 13897)
@@ -71,5 +71,5 @@
 
 Readline   *Readline::This   =  0;
-int         Readline::fLabel = -3;
+bool        Readline::fStopScript = false;
 std::string Readline::fScript;
 
@@ -98,5 +98,5 @@
 //
 Readline::Readline(const char *prgname) :
-    fMaxLines(500), fLine(0), fCompletion(0)
+    fMaxLines(500), fLine(0), fScriptDepth(0), fCompletion(0)
 {
     if (This)
@@ -1011,8 +1011,8 @@
         try
         {
-            const int section = stoi(str.substr(1));
-            SetSection(section);
-
-            if (fLabel!=section)
+            fSection = stoi(str.substr(1));
+            SetSection(fSection);
+
+            if (fLabel!=fSection)
                 return true;
         }
@@ -1073,5 +1073,9 @@
         }
 
+        const int save = fSection;
         Execute(opt, data);
+        fSection = save;
+        SetSection(save);
+
         return true;
     }
@@ -1335,4 +1339,5 @@
     fScript = name;
 
+    fSection = -2;
     SetSection(-2);
     fLabel = -1;
@@ -1348,4 +1353,5 @@
     if (!fin)
     {
+        fSection = -3;
         SetSection(-3);
         return -1;
@@ -1357,4 +1363,8 @@
     fCommandLog << ")" << endl;
 
+    if (fScriptDepth++==0)
+        fStopScript = false;
+
+    fSection = -1;
     SetSection(-1);
 
@@ -1362,5 +1372,5 @@
 
     string buffer;
-    while (getline(fin, buffer, '\n') && fLabel>-2)
+    while (getline(fin, buffer, '\n') && !fStopScript)
     {
         buffer = Tools::Trim(buffer);
@@ -1389,5 +1399,9 @@
 
     fLabel = -1;
+    fSection = -3;
     SetSection(-3);
+
+    if (--fScriptDepth==0)
+        fStopScript = false;
 
     fCommandLog << "# " << Time() << " - " << name << " (FINISHED)" << endl;
Index: /trunk/FACT++/src/RemoteControl.h
===================================================================
--- /trunk/FACT++/src/RemoteControl.h	(revision 13896)
+++ /trunk/FACT++/src/RemoteControl.h	(revision 13897)
@@ -222,21 +222,21 @@
             T::GetStreamOut().SetBacklog(false);
             T::GetStreamOut().SetNullOutput(false);
-            while (l->second->GetState()!=state && timeout>Time() && T::GetLabel()!=-2)
+            while (l->second->GetState()!=state && timeout>Time() && !T::IsScriptStopped())
                 usleep(1);
             T::GetStreamOut().SetNullOutput(true);
             T::GetStreamOut().SetBacklog(true);
 
-            if (T::GetLabel()!=-2 && l->second->GetState()!=state)
-            {
-                int label = -1;
-                in >> label;
-                if (in.fail() && !in.eof())
-                {
-                    lout << kRed << "Invalid label in '" << str.substr(3) << "'" << endl;
-                    label = -2;
-                }
-                else
-                    T::SetLabel(label);
-            }
+            if (l->second->GetState()==state)
+                return true;
+
+            int label = -1;
+            in >> label;
+            if (in.fail() && !in.eof())
+            {
+                lout << kRed << "Invalid label in '" << str.substr(3) << "'" << endl;
+                T::StopScript();
+                return true;
+            }
+            T::SetLabel(label);
 
             return true;
Index: /trunk/FACT++/src/dimctrl.cc
===================================================================
--- /trunk/FACT++/src/dimctrl.cc	(revision 13896)
+++ /trunk/FACT++/src/dimctrl.cc	(revision 13897)
@@ -107,5 +107,5 @@
 
             Debug(msg);
-            Readline::SetLabel(-2);
+            Readline::StopScript();
         }
 
@@ -256,5 +256,5 @@
     }
 
-    void Stop(int stop=0) { fStop = stop; Readline::SetLabel(0); }
+    void Stop(int stop=0) { fStop = stop; Readline::StopScript(); }
     int Run(bool)
     {
