I'm pretty sure this is the best way to do it right now. It might be
possible to use the import machinery directly, but I'm not sure off
the top of my head.

- Jeff

On Sun, Jan 6, 2013 at 4:37 PM, Peter Schwalm <[email protected]> wrote:
> Hello,
>
> I could figure it out myself now, not for a service yet, but for a c#
> console program. If anybody is interested here is the code snippet:
>
>     class Program
>     {
>         static int Main(string[] args)
>         {
>             int rv = 0;
>             // load the dll that results from ipy-compilation
>             string AssemblyName = "outputMgrSvc1";
>             Assembly assembly = Assembly.Load(AssemblyName);
>             Dictionary<string, object> options = new Dictionary<string,
> object>();
>             options["FullFrames"] = true;
>             options["Frames"] = true;
>             options["Tracing"] = true;
>             ScriptRuntime runtime = Python.CreateRuntime(options);
>             ScriptEngine engine = runtime.GetEngine("py");
>             runtime.LoadAssembly(assembly);
>
>             // initialize the script module
>             ScriptScope scope = engine.CreateScope();
>             string sourceString = @"from outputMgrSvc1 import *";
>             ScriptSource source =
> engine.CreateScriptSourceFromString(sourceString,
>                 Microsoft.Scripting.SourceCodeKind.Statements);
>             try
>             {
>                 var x = source.Execute(scope);
>             }
>             catch (IronPython.Runtime.Exceptions.SystemExitException exc)
>             {
>                 object other;
>                 rv = exc.GetExitCode(out other);
>                 return rv;
>             }
>
>             // execute main procedure of script
>             ObjectOperations ops = engine.Operations;
>             dynamic names = scope.GetVariableNames();   // look at module
> data/procs
>             dynamic proc = scope.GetVariable("scriptMain");
>             try
>             {
>                 rv = proc();
>             }
>             catch (IronPython.Runtime.Exceptions.SystemExitException exc)
>             {
>                 object other;
>                 rv = exc.GetExitCode(out other);
>             }
>             return rv;
>         }
>     }
>
> Thank you
> Peter
>
> Am 04.01.2013 16:04, schrieb Peter Schwalm:
>
>> Hello,
>> I want to use the embedding feature of ipy for implementing an ipy program
>> as a windows service. I hope I can benefit from the good support of Visual
>> Studio and C# for the installation of services (installUtil.exe).
>>
>> My question is: is it possible to use pyc-compiled programs with the
>> embedding features?
>>
>> My plan is to code like this
>>
>>     using IronPython.Hosting;
>>     using IronPython.Runtime;
>>     using Microsoft.Scripting.Hosting;
>>     ...
>>
>>     ipyRt = Python.CreateRuntime()
>>     dynamic testPy = ipyRt.UseFile("program....py");
>>     ...
>>     testPy.function()
>>
>> Is it possible to use compiled modules instead of "program....py" with
>> .UseFile?
>>
>> Thanks in advance
>> Peter
>>
>> _______________________________________________
>> Ironpython-users mailing list
>> [email protected]
>> http://mail.python.org/mailman/listinfo/ironpython-users
>>
>
> _______________________________________________
> Ironpython-users mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/ironpython-users
_______________________________________________
Ironpython-users mailing list
[email protected]
http://mail.python.org/mailman/listinfo/ironpython-users

Reply via email to