![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Handling param statement in custom host application I have written a WinForms application that hosts powershell. The problem is that some of the scripts I want to run through my host contain the "param" statement at the beginning of them. It seems that the Microsoft PowerShell host application looks for this and does something special with it in order to hook up the parameter references in the script and the parameter values. "param" doesn't seem to be processed by the pipeline anyhow and is says it's not recognised at a cmdlet, function etc. Any help as to how a process the "param" statement in my Powershell host would be appreciated. Thanks |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Handling param statement in custom host application Could you please provide a piece of code that fails and\or a script with "param" that causes this failure? (side note: I develop a PS host application for quite a long time and I have never seen this problem) -- Thanks, Roman Kuzmin http://code.google.com/p/farnet/ PowerShell and .NET in FAR Manager |
My System Specs![]() |
| | #3 (permalink) | ||||||||||||
| Guest | Re: Handling param statement in custom host application "Roman Kuzmin" wrote:
week. When you call pipeline.Commands.AddScript("Param([String] $VarA) \r\n"+ "echo $VarA"); the error will occur. If you save the same two lines to a file and then call pipeline.Commands.Add( name of file ); everything works fine | ||||||||||||
My System Specs![]() | |||||||||||||
| | #4 (permalink) |
| Guest | Re: Handling param statement in custom host application NJBrad, It's not too late :-) *) I think that two commands you provided are not the same at all (the second is correct, indeed). *) I am not sure what you are going to do with the first command (still not enough the code). Thinking in pure PowerShell it looks rather like the code: Param([String] $VarA); echo $VarA | ... or .... | Param([String] $VarA); echo $VarA or .... | Param([String] $VarA); echo $VarA | ... or ??? In any case syntax is odd and apparently not correct. I cannot play with it just now, so that I would recommend you to try to use a script block, i.e. pipeline.Commands.AddScript("{ Param ... }") (or perhaps this: pipeline.Commands.AddScript("&{ Param ... }") which corresponds to at least valid and working (at least in V2) syntax: 0> & {param($vara); echo $vara } 'foo' foo -- Thanks, Roman Kuzmin http://code.google.com/p/farnet/ PowerShell and .NET in FAR Manager |
My System Specs![]() |
| | #5 (permalink) | ||||||||||||
| Guest | Re: Handling param statement in custom host application "Roman Kuzmin" wrote:
stripped down script showing the problem. I want to be able to pass a named parameter into a script. I want the same script to be able to be run from PowerShell itself and also from within my own host. Taking the exact same text that is in a file and calling AddScript "should" do the same thing. The only difference I'm running into is the param at the beginning of the script. Wrapping the script with { and } doesn't yield the same result as running it by itself. | ||||||||||||
My System Specs![]() | |||||||||||||
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Exception Handling Application Block | Polly Anna | .NET General | 2 | 05-17-2008 10:22 AM |
| Handling Application.Start via Custom HTTP Module | Cramer | .NET General | 0 | 04-23-2008 02:55 AM |
| Custom Exception Handling And Logging using EnterPrise Library app | Shrikant More | .NET General | 0 | 03-31-2008 12:08 AM |
| Exception handling in Vista Application | Aale de Winkel | Vista General | 0 | 04-16-2007 05:24 AM |
| Handling Drag Events in Custom Control | viRtual | Avalon | 2 | 06-04-2006 10:00 PM |