CodePlexProject Hosting for Open Source Software
I have been trying to write a lite custom host that needs to communcate with cmdlets in a singlerunspace from PSHostRawUserInterface object. I thought if I could access the runspace session state I would be able to get/set PSVariables. If that
is not possible I also noticed that cmdlets can communicate to/from the host by using the PrivateData property. There is precious little documentation on PrivateData. Does any body have any ideas or suggestions on how this can be done? You
would think this would be simple.
Each Runspace you create has a SessionStateProxy object on which there are two methods: GetVariable() and SetVariable(). Those should do the trick for you.
Actually I tried this. I get a PSInvalidOperationException: A pipeline is already executing. Concurrent SessionStateProxy method call is not allowed. Below is a real basic example. I pass the runspace
object as a Runspace property in my PSHostUserInterface class. The exception is thrown on the GetVariable method.
Let me try again. Formatting issue.
public override void WriteLine(string value)
string psHome = (string)runspace.SessionStateProxy.GetVariable("PSHOME");
Console.WriteLine("Home: " + psHome);
Try getting/setting the variables before you start executing commands/script within the runspace.
Unfortunately, I can't do that. The variable can change within the runspace. That is why I thought the host's PrivateData property could be used. For example a cmdlet or script can set a property like $host.privatedata.ErrorForegroundColor.
The problem is I can't figure out how to implement it. The documentation in the SDK regarding this property is not clear.
Are you sure you want to delete this post? You will not be able to recover it later.
Are you sure you want to delete this thread? You will not be able to recover it later.