--- a/trunk/cforge/cforge/Helper.cs +++ b/trunk/cforge/cforge/Helper.cs @@ -152,6 +152,19 @@ return @"C:\Program Files (x86)\3S CODESYS\CODESYS\"; } + /// <summary> + /// Function to retrieve the "ScriptLib" Path inside CODESYS. We just take the last one, probably this is the newest one + /// </summary> + /// <returns>full path to ScriptLib version folder</returns> + private static String GetCODESYSScriptingLibPath() + { + String path = Path.Combine(GetCODESYSRoot(), "ScriptLib"); + String version = Directory.EnumerateDirectories(path).Last(); + + path = Path.Combine(path, version); + + return path; + } /// <summary> /// Function to retrieve the CFORGE Script path (this is where the IronPython scripts should reside) @@ -255,15 +268,28 @@ ScriptEngine engine = IronPython.Hosting.Python.CreateEngine(new Dictionary<string, object> { { "Debug", ScriptingRuntimeHelpers.True } }); Debug.Assert(engine.Runtime.Setup.DebugMode); + String strScriptingPath = GetCODESYSScriptingLibPath(); + try { dynamic sys = Python.GetSysModule(engine); sys.argv = args; - + sys.path.Add(strScriptingPath); + var source = engine.CreateScriptSourceFromFile(scriptfile); dynamic result = source.Execute(); //Console.WriteLine("Script finished"); + } + catch (IronPython.Runtime.Exceptions.SystemExitException ex) + { + Console.WriteLine(); + + Console.WriteLine("[INFO] command " + command + ".py exited: "); + + ExceptionOperations eo = engine.GetService<ExceptionOperations>(); + string error = "[INFO] " + eo.FormatException(ex); + Console.WriteLine(error); } catch (Exception ex) {