How can I host PowerShell 3.0 in a c# app using a similar API to other DLR languages
Asked Answered
L

2

8

I've been playing with a c# app that hosts IronPython, IronRuby, and (hopefully) PowerShell. Since IronPython and IronRuby were completely built on the DLR, the API for using them is pretty much identical.

IronPython.Hosting.Python.CreateEngine()

and

IronRuby.Ruby.CreateEngine()

both create instances of a Microsoft.Scripting.Hosting.ScriptEngine. Is there any hope of coercing PowerShell 3.0 to create a ScriptEngine? I have not been able to find much on the subject, other than PowerShell 3.0 seem be built on the DLR more than the previous version was (see http://huddledmasses.org/powershell-3-finally-on-the-dlr.

It doesn't appear that you can cast a PowerShell engine created with the following to a ScriptEngine.

System.Management.Automation.PowerShell.Create()

I suspect that if I really want to handle PowerShell through the same API I need to create my own ScriptEngine that wraps the PowerShell host.

Lp answered 22/7, 2012 at 2:16 Comment(0)
C
4

PowerShell V3 does indeed use some of the DLR, but only parts that shipped in the .Net Frameworks V4. The DLR project had many useful apis that were not included in .Net, e.g. Microsoft.Scripting.Hosting.ScriptEngine.

If PowerShell wanted to implement the ScriptEngine apis, PowerShell would have had to ship those apis as part of PowerShell. The PowerShell team wasn't willing to take ownership of those apis.

So you are correct in assuming you need to wrap PowerShell with your own code if you want to implement ScriptEngine.

Calibre answered 24/9, 2013 at 0:2 Comment(0)
A
-1

PowerShell works with dotnet assembly and is very interesting when you have a administrator profil and you want to make advanced instructions.But you are a developper so why wrapping PowerShell, you can access all dotnet assembly from your code.It is better to code what you want instead of wrapping PowerShell Best regard

Apposition answered 22/7, 2012 at 7:51 Comment(1)
I know how powerful PowerShell can be. I'm trying build my own scripting environment to learn about embedding DLR languages. I really want to be able to have PowerShell and IronPython in the same environment. Most DLR languages behave the same in terms of embedding them. PowerShell predates the DLR, so I was wondering if there is any way to make it behave like other DLR languages.Lp

© 2022 - 2024 — McMap. All rights reserved.