Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts Windows 7 Forum 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

mixing old-style (text) pipe components

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 03-22-2007   #1 (permalink)
wscholine
Guest


 

mixing old-style (text) pipe components

I have this win32 command, call it cmd. It writes some text to stdout.

If in ps I do

cmd | gm

I get

TypeName: System.String

Name MemberType Definition
---- ---------- ----------
Clone Method System.Object Clone()
....

If I do

(cmd).length

I get 38, which is the number of lines of text that cmd prints.

If I do (cmd)[0..5] I get the first 6 lines of the output. Which seems
to say that (cmd) is really an array of strings. Why does gm say it's
System.String? If I do

cmd | % { $_ something }

is $_ a line of output from cmd, or the whole array?

If I have another win32 command, call it cmd2, which expects to read
lines from stdin, and I want to do

cmd | assorted ps cmdlets/scriptblocks/whatever | cmd2

do I have to arrange for the last part of the pipeline to translate
its output somehow so that cmd2 will see lines of text?


My System SpecsSystem Spec
Old 03-22-2007   #2 (permalink)
/\\/\\o\\/\\/ [MVP]
Guest


 

Re: mixing old-style (text) pipe components

comments inline

"wscholine" <wscholine@gmail.com> wrote in message
news:1174578281.370873.269160@l75g2000hse.googlegroups.com...
>I have this win32 command, call it cmd. It writes some text to stdout.
>
> If in ps I do
>
> cmd | gm
>
> I get
>
> TypeName: System.String
>
> Name MemberType Definition
> ---- ---------- ----------
> Clone Method System.Object Clone()
> ...
>
> If I do
>
> (cmd).length
>
> I get 38, which is the number of lines of text that cmd prints.
>
> If I do (cmd)[0..5] I get the first 6 lines of the output. Which seems
> to say that (cmd) is really an array of strings. Why does gm say it's
> System.String?


the array of strings will be enumerated on the pipeline hence get-member
will show the properties of elements in the array

PoSH> $abc | gm


TypeName: System.String

to get the collection you can add a comma in front (in effect wrapping it
again in an array)

PoSH> ,$abc | gm


TypeName: System.Object[]

or you can pass it in as a parameter to get-member, also avoiding the
enumerating on the pipeline

PoSH> Get-Member -InputObject $abc


TypeName: System.Object[]

> If I do
>
> cmd | % { $_ something }
>
> is $_ a line of output from cmd, or the whole array?


one line of output, as % is an alias for the foreach-object cmdlet that will
run the scriptblock for every element.

>
> If I have another win32 command, call it cmd2, which expects to read
> lines from stdin, and I want to do
>
> cmd | assorted ps cmdlets/scriptblocks/whatever | cmd2
>
> do I have to arrange for the last part of the pipeline to translate
> its output somehow so that cmd2 will see lines of text?
>


this should work seamless as the PowerShell parser will handle this,
but to make sure you get the text as one string you might use out-string
first

h.t.h.

Greetings /\/\o\/\/

My System SpecsSystem Spec
Old 03-23-2007   #3 (permalink)
Jonathan Prater
Guest


 

Re: mixing old-style (text) pipe components

Comments at bottom...

/\/\o\/\/ [MVP] wrote:
> comments inline
>
> "wscholine" <wscholine@gmail.com> wrote in message
> news:1174578281.370873.269160@l75g2000hse.googlegroups.com...
>> I have this win32 command, call it cmd. It writes some text to stdout.
>>
>> If in ps I do
>>
>> cmd | gm
>>
>> I get
>>
>> TypeName: System.String
>>
>> Name MemberType Definition
>> ---- ---------- ----------
>> Clone Method System.Object Clone()
>> ...
>>
>> If I do
>>
>> (cmd).length
>>
>> I get 38, which is the number of lines of text that cmd prints.
>>
>> If I do (cmd)[0..5] I get the first 6 lines of the output. Which seems
>> to say that (cmd) is really an array of strings. Why does gm say it's
>> System.String?

>
> the array of strings will be enumerated on the pipeline hence get-member
> will show the properties of elements in the array
>
> PoSH> $abc | gm
>
>
> TypeName: System.String
>
> to get the collection you can add a comma in front (in effect wrapping
> it again in an array)
>
> PoSH> ,$abc | gm
>
>
> TypeName: System.Object[]
>
> or you can pass it in as a parameter to get-member, also avoiding the
> enumerating on the pipeline
>
> PoSH> Get-Member -InputObject $abc
>
>
> TypeName: System.Object[]
>
>> If I do
>>
>> cmd | % { $_ something }
>>
>> is $_ a line of output from cmd, or the whole array?

>
> one line of output, as % is an alias for the foreach-object cmdlet that
> will run the scriptblock for every element.
>
>>
>> If I have another win32 command, call it cmd2, which expects to read
>> lines from stdin, and I want to do
>>
>> cmd | assorted ps cmdlets/scriptblocks/whatever | cmd2
>>
>> do I have to arrange for the last part of the pipeline to translate
>> its output somehow so that cmd2 will see lines of text?
>>

>
> this should work seamless as the PowerShell parser will handle this,
> but to make sure you get the text as one string you might use out-string
> first
>
> h.t.h.
>
> Greetings /\/\o\/\/


Suppose I run psinfo (from Sysinternals PSTools) from _within_ PoSh and
pipe that to where-object to find something. How is psinfo's output
treated? As an array of strings, or as something else?
My System SpecsSystem Spec
Old 03-23-2007   #4 (permalink)
Michel Klomp
Guest


 

Re: mixing old-style (text) pipe components

The output from psinfo is treated as an array of strings
If you put the output from psinfo into a variable, you can use gettype.

PS C:\Sysinternals\Pstools> $a = C:\Sysinternals\Pstools\Psinfo.exe
PS C:\Sysinternals\Pstools> $a.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array

PS C:\Sysinternals\Pstools> $a.Length
18

Michel Klomp


"Jonathan Prater" <jonathan.prater@gmail.com> wrote in message
news:uqrPFjTbHHA.4476@TK2MSFTNGP03.phx.gbl...
> Comments at bottom...
>
> /\/\o\/\/ [MVP] wrote:
>> comments inline
>>
>> "wscholine" <wscholine@gmail.com> wrote in message
>> news:1174578281.370873.269160@l75g2000hse.googlegroups.com...
>>> I have this win32 command, call it cmd. It writes some text to stdout.
>>>
>>> If in ps I do
>>>
>>> cmd | gm
>>>
>>> I get
>>>
>>> TypeName: System.String
>>>
>>> Name MemberType Definition
>>> ---- ---------- ----------
>>> Clone Method System.Object Clone()
>>> ...
>>>
>>> If I do
>>>
>>> (cmd).length
>>>
>>> I get 38, which is the number of lines of text that cmd prints.
>>>
>>> If I do (cmd)[0..5] I get the first 6 lines of the output. Which seems
>>> to say that (cmd) is really an array of strings. Why does gm say it's
>>> System.String?

>>
>> the array of strings will be enumerated on the pipeline hence get-member
>> will show the properties of elements in the array
>>
>> PoSH> $abc | gm
>>
>>
>> TypeName: System.String
>>
>> to get the collection you can add a comma in front (in effect wrapping it
>> again in an array)
>>
>> PoSH> ,$abc | gm
>>
>>
>> TypeName: System.Object[]
>>
>> or you can pass it in as a parameter to get-member, also avoiding the
>> enumerating on the pipeline
>>
>> PoSH> Get-Member -InputObject $abc
>>
>>
>> TypeName: System.Object[]
>>
>>> If I do
>>>
>>> cmd | % { $_ something }
>>>
>>> is $_ a line of output from cmd, or the whole array?

>>
>> one line of output, as % is an alias for the foreach-object cmdlet that
>> will run the scriptblock for every element.
>>
>>>
>>> If I have another win32 command, call it cmd2, which expects to read
>>> lines from stdin, and I want to do
>>>
>>> cmd | assorted ps cmdlets/scriptblocks/whatever | cmd2
>>>
>>> do I have to arrange for the last part of the pipeline to translate
>>> its output somehow so that cmd2 will see lines of text?
>>>

>>
>> this should work seamless as the PowerShell parser will handle this,
>> but to make sure you get the text as one string you might use out-string
>> first
>>
>> h.t.h.
>>
>> Greetings /\/\o\/\/

>
> Suppose I run psinfo (from Sysinternals PSTools) from _within_ PoSh and
> pipe that to where-object to find something. How is psinfo's output
> treated? As an array of strings, or as something else?


My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Pipe a pipe command to a file WB VB Script 4 07-15-2008 09:03 PM
Adding & Mixing RAM.. PLZ HELP!! xguntherc Vista performance & maintenance 14 03-15-2008 08:39 PM
Font Size - XP style vs Vista style John M. Dlugosz Vista General 0 02-24-2008 12:46 AM
Font Size - XP style vs Vista style John M. Dlugosz Vista General 0 02-19-2008 06:48 PM
Font Size - XP style vs Vista style John M. Dlugosz Vista General 1 02-19-2008 09:57 AM


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