![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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 | 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 Specs![]() |
| | #2 (permalink) |
| 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 Specs![]() |
| | #3 (permalink) |
| 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 Specs![]() |
| | #4 (permalink) |
| 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 Specs![]() |
![]() |
| 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 |