Index: trunk/FACT++/src/Main.h
===================================================================
--- trunk/FACT++/src/Main.h	(revision 14544)
+++ trunk/FACT++/src/Main.h	(revision 14545)
@@ -191,4 +191,13 @@
         thread t(bind(Main::Thread, &io_service, dummy, ref(ret)));
 
+        // Wait until state machine is ready (The only case I can imagine
+        // in which the state will never chane is when DIM triggers
+        // an exit before the state machine has been started at all.
+        // Hopefully checking the readline (see Threed) should fix
+        // that -- difficult to test.)
+        while (io_service.GetCurrentState()<StateMachineImp::kSM_Ready && !shell.IsStopped())
+            usleep(1);
+
+        // Execute command line commands
         const vector<string> v1 = conf.Vec<string>("cmd");
         for (vector<string>::const_iterator it=v1.begin(); it!=v1.end(); it++)
@@ -199,6 +208,7 @@
             shell.Execute(*it, args);
 
+        // Run the shell if no immediate exit was requested
         if (!conf.Get<bool>("quit"))
-            shell.Run();             // Run the shell
+            shell.Run();
 
         io_service.Stop();           // Signal Loop-thread to stop
