Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Handling param statement in custom host application

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 05-15-2008   #1 (permalink)
paul
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 SpecsSystem Spec
Old 05-15-2008   #2 (permalink)
Roman Kuzmin
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 SpecsSystem Spec
Old 08-06-2008   #3 (permalink)
NJBrad
Guest


 

Re: Handling param statement in custom host application



"Roman Kuzmin" wrote:
Quote:

> 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
>
>
I know this is rather late in the thread, but I ran into the same issue this
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 SpecsSystem Spec
Old 08-07-2008   #4 (permalink)
Roman Kuzmin
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 SpecsSystem Spec
Old 08-07-2008   #5 (permalink)
NJBrad
Guest


 

Re: Handling param statement in custom host application



"Roman Kuzmin" wrote:
Quote:

> 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
>
>
I'm trying to execute the exact same thing in PowerShell. This is a
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 SpecsSystem Spec
Closed Thread

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


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51