[IronPython] Embedding Powershell and Write-Host

Curt Hagenlocher curt at hagenlocher.org
Wed Jan 14 01:06:19 CET 2009

You might find this link helpful.  It was the second hit when googling
"implement pshost", and the author talks about integration between IronRuby
and PowerShell.

On Tue, Jan 13, 2009 at 3:58 PM, Stephen Ng <stephen at theleengs.com> wrote:

> I'm using the following code to embed Powershell into IronPython.  I hope
> to eventually replace almost all of my (large) Powershell script with
> IronPython.
>   from System.Management.Automation.Runspaces import RunspaceFactory
>   the_runspace = RunspaceFactory.CreateRunspace()
>   the_runspace.Open()
>   ri = RunspaceInvoke(the_runspace)
>   out = ri.Invoke('. .\myscript.ps1')
> I'm able to pass variables back and forth using
> the_runspace.SessionStateProxy.Get/SetVariable, which is really cool.
> My problem is that any calls to Write-Host fail with "Cannot invoke this
> function becasue the current host does not implement it."  Of course I can
> remove all the Write-Host's, but I really depend on them for status
> information about how my script is running, and not having access to console
> output makes my script much harder to debug.
> This post: http://decav.co<http://decav.com/blogs/andre/archive/2008/05/01/invoking-powershell-scripts-from-an-application.aspx>
> m/blogs/andre/a<http://decav.com/blogs/andre/archive/2008/05/01/invoking-powershell-scripts-from-an-application.aspx>
> rchive/2008/05/<http://decav.com/blogs/andre/archive/2008/05/01/invoking-powershell-scripts-from-an-application.aspx>
> 01/invoking-pow<http://decav.com/blogs/andre/archive/2008/05/01/invoking-powershell-scripts-from-an-application.aspx>
> ershell-scripts<http://decav.com/blogs/andre/archive/2008/05/01/invoking-powershell-scripts-from-an-application.aspx>
> -from-an-applic<http://decav.com/blogs/andre/archive/2008/05/01/invoking-powershell-scripts-from-an-application.aspx>
> ation.aspx<http://decav.com/blogs/andre/archive/2008/05/01/invoking-powershell-scripts-from-an-application.aspx> says
> "To get around this, you can remove *write-host* from your scripts and
> just have them write single lines, or you can implement a simple *PSHost* (although
> this is a bit harder than it sounds)."
> What does "just have them write single lines mean?"  Any pointers on how I
> can get this working under IronPython?
> Thanks,
> Steve
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20090113/d20c6437/attachment.html>

More information about the Ironpython-users mailing list