static void Main(string[] args)
{
// set path for dynamic assembly loading
AppDomain.CurrentDomain.AssemblyResolve +=
new ResolveEventHandler(ResolveAssembly);
string path = System.IO.Path.Combine(exe_path, py_path);
pyscript = System.IO.Path.Combine(path, pyscript);
pyscript = System.IO.Path.GetFullPath(pyscript); // normalize
// get runtime
ScriptRuntimeSetup scriptRuntimeSetup = new ScriptRuntimeSetup();
LanguageSetup language = Python.CreateLanguageSetup(null);
language.Options["Debug"] = true;
scriptRuntimeSetup.LanguageSetups.Add(language);
ScriptRuntime runtime = new Microsoft.Scripting.Hosting.ScriptRuntime(scriptRuntimeSetup);
// set sys.argv
SetPyEnv(runtime, pyscript, args);
// get engine
ScriptScope scope = runtime.CreateScope();
ScriptEngine engine = runtime.GetEngine("python");
ScriptSource source = engine.CreateScriptSourceFromFile(pyscript);
source.Compile();
try {
source.Execute(scope);
} catch (IronPython.Runtime.Exceptions.SystemExitException e) {
Console.WriteLine(e.StackTrace);
}
}