On Mar 25, 8:53*pm, "Oisin (x0n) Grehan [MVP]" <ois...@xxxxxx>
wrote:
> On Mar 25, 4:56*pm, RickB <rbiel...@xxxxxx> wrote:
>
>
>
>
>
> > I need to wrap an arbitrary script call with some code. >
> > function some-function ($a,$b) {"`$a is '$a' and `$b is '$b'"}
> > function Wrapper ($fcn) {
> > * * Some_wrapper_code
> > * * &$fcn $args} >
> > Wrapper some-function arbitrary args >
> > I can't seem to figure out how to expand/explode $args
> > so that $fcn gets the same value for $args that Wrapper got. >
> > Rather than
> > $a is 'arbitrary' and $b is 'args'
> > I end up with
> > $a is 'arbitrary args' and $b is '' >
> > Since the function is arbitrary I can't know the number or type of
> > parameters in advance. >
> As Keith mentioned, v2 has a splatting operator. V1 does not. However:
>
> * function some-function ($a,$b) {"`$a is '$a' and `$b is '$b'"}
>
> * function wrapper ($fcn) {
> * * * # wrapper code
>
> * * * $Args | % -begin {
> * * * * * $exp = "$fcn " } -process {
> * * * * * $exp += "$_ " } -end {
> * * * * * Invoke-Expression $exp
> * * * }
> * *}
>
> PS> wrapper some-function x y
> $a is 'x' and $b is 'y'
>
> yeah, its smells funny, but it works.
>
> - Oisin- Hide quoted text -
>
> - Show quoted text - I have 2.0 and so I thought I wouldn't need to use this.
It turns out that one machine I need my stuff to run on
can't run 2.0 .. forcing me to be 1.0 compatible.
Now I finally tried your method and discover it only works
when the arguments are all strings. Some of my params
are objects so they didn't make it thru.
This finally did work though.
$Args | % -begin {
$exp = "$fcn "
$cntr = 0} -process {
set-variable ('tmp'+ ++$cntr) $_
$exp += "`$$('tmp' + $cntr) " } -end {
Invoke-Expression $exp}