Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista Tutorial - Script parameter problem

Reply
 
Old 08-07-2008   #1 (permalink)
Test
Guest


 
 

Script parameter problem

Hi,

there are two scripts

test1.ps1:
Quote:

> $Args
test2.ps1:
Quote:

> $i = "'1234 5678' 22 33 zzz"
> ./test1 $i
Running test2 -> Output
Quote:

> '1234 5678' 22 33 zzz
but it should be like
test3.ps1:
Quote:

> ./test1 '1234 5678' 22 33 zzz
Running test3 -> Output:
Quote:

> 1234 5678
> 22
> 33
> zzz
How can I use a normal string - without converting it to an array - as a
variable. Or I'm totally blind?

My System SpecsSystem Spec
Old 08-07-2008   #2 (permalink)
Neil Chambers
Guest


 
 

Re: Script parameter problem

I'm not quite sure what you mean but each space denotes a new argument
(multiple spaces mean more arguments which get bundled into an array) so
using the approach you used to assign to $i is correct for specifying a
single argument

../test1 "'1234 5678' 22 33 zzz"

n


"Test" <olli.marx@xxxxxx> wrote in message
news:%23xEdbDN%23IHA.4784@xxxxxx
Quote:

> Hi,
>
> there are two scripts
>
> test1.ps1:
Quote:

> > $Args
>
> test2.ps1:
Quote:

> > $i = "'1234 5678' 22 33 zzz"
> > ./test1 $i
>
> Running test2 -> Output
Quote:

> > '1234 5678' 22 33 zzz
>
> but it should be like
> test3.ps1:
Quote:

> > ./test1 '1234 5678' 22 33 zzz
>
> Running test3 -> Output:
Quote:

> > 1234 5678
> > 22
> > 33
> > zzz
>
> How can I use a normal string - without converting it to an array - as a
> variable. Or I'm totally blind?
My System SpecsSystem Spec
Old 08-07-2008   #3 (permalink)
Oliver
Guest


 
 

Re: Script parameter problem

Hi Neil,
Quote:

> I'm not quite sure what you mean but each space denotes a new argument
> (multiple spaces mean more arguments which get bundled into an array) so
> using the approach you used to assign to $i is correct for specifying a
> single argument
That's right. But I want 'expand' $i in that way, that $i becomes the
commandline

../test1 '1234 5678' 22 33 zzz

and not

../test1 "'1234 5678' 22 33 zzz"

Cheers,
Oliver
Quote:

> "Test" <olli.marx@xxxxxx> wrote in message
> news:%23xEdbDN%23IHA.4784@xxxxxx
Quote:

>> Hi,
>>
>> there are two scripts
>>
>> test1.ps1:
Quote:

>> > $Args
>>
>> test2.ps1:
Quote:

>> > $i = "'1234 5678' 22 33 zzz"
>> > ./test1 $i
>>
>> Running test2 -> Output
Quote:

>> > '1234 5678' 22 33 zzz
>>
>> but it should be like
>> test3.ps1:
Quote:

>> > ./test1 '1234 5678' 22 33 zzz
>>
>> Running test3 -> Output:
Quote:

>> > 1234 5678
>> > 22
>> > 33
>> > zzz
>>
>> How can I use a normal string - without converting it to an array - as
>> a variable. Or I'm totally blind?
>
My System SpecsSystem Spec
Old 08-08-2008   #4 (permalink)
Neil Chambers
Guest


 
 

Re: Script parameter problem

ahh - I think I see - you actually want unique parameters but you want to
avoid using an array to build the input argument. Yes, I see now this is
what you meant.

I have absolutely no idea how to achieve that In order for $i to
separate the parameters it must (AFAIK) be an array OR you must convert $i
into an array when you pass it through. Using a Split() wouldn't work for
the example you've given but some regular expression jiggerypokery might do
it. Sadly my regex skilz are not that great.

soz
n

"Oliver" <olli.marx@xxxxxx> wrote in message
news:uCfg5pQ%23IHA.5056@xxxxxx
Quote:

> Hi Neil,
>
Quote:

>> I'm not quite sure what you mean but each space denotes a new argument
>> (multiple spaces mean more arguments which get bundled into an array) so
>> using the approach you used to assign to $i is correct for specifying a
>> single argument
>
> That's right. But I want 'expand' $i in that way, that $i becomes the
> commandline
>
> ./test1 '1234 5678' 22 33 zzz
>
> and not
>
> ./test1 "'1234 5678' 22 33 zzz"
>
> Cheers,
> Oliver
>
Quote:

>> "Test" <olli.marx@xxxxxx> wrote in message
>> news:%23xEdbDN%23IHA.4784@xxxxxx
Quote:

>>> Hi,
>>>
>>> there are two scripts
>>>
>>> test1.ps1:
>>> > $Args
>>>
>>> test2.ps1:
>>> > $i = "'1234 5678' 22 33 zzz"
>>> > ./test1 $i
>>>
>>> Running test2 -> Output
>>> > '1234 5678' 22 33 zzz
>>>
>>> but it should be like
>>> test3.ps1:
>>> > ./test1 '1234 5678' 22 33 zzz
>>>
>>> Running test3 -> Output:
>>> > 1234 5678
>>> > 22
>>> > 33
>>> > zzz
>>>
>>> How can I use a normal string - without converting it to an array - as a
>>> variable. Or I'm totally blind?
>>
My System SpecsSystem Spec
Old 08-08-2008   #5 (permalink)
Oisin (x0n) Grehan [MVP]
Guest


 
 

Re: Script parameter problem

On Aug 7, 11:54*pm, Oliver <olli.m...@xxxxxx> wrote:
Quote:

> Hi Neil,
>
Quote:

> > I'm not quite sure what you mean but each space denotes a new argument
> > (multiple spaces mean more arguments which get bundled into an array) so
> > using the approach you used to assign to $i is correct for specifying a
> > single argument
>
> That's right. But I want 'expand' $i in that way, that $i becomes the
> commandline
>
> ./test1 '1234 5678' 22 33 zzz
>
> and not
>
> ./test1 "'1234 5678' 22 33 zzz"
>
> Cheers,
> Oliver
>
>
>
Quote:

> > "Test" <olli.m...@xxxxxx> wrote in message
> >news:%23xEdbDN%23IHA.4784@xxxxxx
Quote:

> >> Hi,
>
Quote:
Quote:

> >> there are two scripts
>
Quote:
Quote:

> >> test1.ps1:
> >> > $Args
>
Quote:
Quote:

> >> test2.ps1:
> >> > $i = "'1234 5678' 22 33 zzz"
> >> > ./test1 $i
>
Quote:
Quote:

> >> Running test2 -> Output
> >> > '1234 5678' 22 33 zzz
>
Quote:
Quote:

> >> but it should be like
> >> test3.ps1:
> >> > ./test1 '1234 5678' 22 33 zzz
>
Quote:
Quote:

> >> Running test3 -> Output:
> >> > 1234 5678
> >> > 22
> >> > 33
> >> > zzz
>
Quote:
Quote:

> >> How can I use a normal string - without converting it to an array - as
> >> a variable. Or I'm totally blind?- Hide quoted text -
>
> - Show quoted text -
Hi,

Try:

ps c:\> invoke-expression ".\test1.ps1 $i"

Hope this helps,

- Oisin

PowerShell MVP
http://www.nivot.org/

My System SpecsSystem Spec
Old 08-08-2008   #6 (permalink)
Oliver
Guest


 
 

Re: Script parameter problem

Hi Neil,
Quote:

> ahh - I think I see - you actually want unique parameters but you want
> to avoid using an array to build the input argument. Yes, I see now this
> is what you meant.
It's a string. And PS should do the work for me.
Quote:

> I have absolutely no idea how to achieve that In order for $i to
> separate the parameters it must (AFAIK) be an array OR you must convert
> $i into an array when you pass it through. Using a Split() wouldn't work
> for the example you've given but some regular expression jiggerypokery
> might do it. Sadly my regex skilz are not that great.
Regex is an solution, but it is a very tricky to handle: e.g. special
chars whit special meanings like " ' `

Cheers,
Oliver
Quote:

> soz
> n
>
> "Oliver" <olli.marx@xxxxxx> wrote in message
> news:uCfg5pQ%23IHA.5056@xxxxxx
Quote:

>> Hi Neil,
>>
Quote:

>>> I'm not quite sure what you mean but each space denotes a new
>>> argument (multiple spaces mean more arguments which get bundled into
>>> an array) so using the approach you used to assign to $i is correct
>>> for specifying a single argument
>>
>> That's right. But I want 'expand' $i in that way, that $i becomes the
>> commandline
>>
>> ./test1 '1234 5678' 22 33 zzz
>>
>> and not
>>
>> ./test1 "'1234 5678' 22 33 zzz"
>>
>> Cheers,
>> Oliver
>>
Quote:

>>> "Test" <olli.marx@xxxxxx> wrote in message
>>> news:%23xEdbDN%23IHA.4784@xxxxxx
>>>> Hi,
>>>>
>>>> there are two scripts
>>>>
>>>> test1.ps1:
>>>> > $Args
>>>>
>>>> test2.ps1:
>>>> > $i = "'1234 5678' 22 33 zzz"
>>>> > ./test1 $i
>>>>
>>>> Running test2 -> Output
>>>> > '1234 5678' 22 33 zzz
>>>>
>>>> but it should be like
>>>> test3.ps1:
>>>> > ./test1 '1234 5678' 22 33 zzz
>>>>
>>>> Running test3 -> Output:
>>>> > 1234 5678
>>>> > 22
>>>> > 33
>>>> > zzz
>>>>
>>>> How can I use a normal string - without converting it to an array -
>>>> as a variable. Or I'm totally blind?
>>>
>
My System SpecsSystem Spec
Old 08-08-2008   #7 (permalink)
Oliver
Guest


 
 

Re: Script parameter problem

Hi Oisin,
Quote:

> Hi,
>
> Try:
>
> ps c:\> invoke-expression ".\test1.ps1 $i"
>
> Hope this helps,
Seems to work - thank you very much!

Cheers,
Oliver
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
using foreach-object as a parameter for another script PowerShell
Script switch parameter as variable PowerShell
CTP: Script cmdlet parameter attributes error PowerShell
Passing a string array as a parameter from one script to another PowerShell
Passing a HashTable object as a parameter to a script PowerShell


Vista Forums 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 Ltd

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