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 - rule of tee-object ?

Reply
 
Old 05-20-2006   #1 (permalink)
Jean


 
 

rule of tee-object ?

By reading "help tee-object" it isn't clear for me about its intended
rule(s).

When we read :

"Sends input objects to two places."

and in EXAMPLE 1 description :

"Since there is no *second* path listed, the result will be displayed
in the console."

and in EXAMPLE 2 description :

" This example gets the list of processes *and* sends the result to a
file and creates a variable, the value of which will be the list."

we must think tee-object has the ability to do two things
simulteanously.

But it isn't.

We could think there is a mistake in EXAMPLE 2

Get-Process notepad | Tee-Object -Variable proc

and try something like

Get-Process notepad | Tee-Object -Variable proc -file
C:\Test1\testfile2.txt

.... but that doesn't work.

Reading USAGE in help we see that there are two syntaxes : one with
-FilePath and one with -Variable.
Reading PARAMETERS in help we see that those two parameters are
"parameter required".
An it's as it works :
tee-object works with -FilePath *or* -Variable but not with -FilePath
*and* -Variable.

So, I am confused about what tee-object really do an what it was
supposed to do ...

Regards,

--
Jean - JMST
Belgium



My System SpecsSystem Spec
Old 05-20-2006   #2 (permalink)
Jouko Kynsijärvi


 
 

Re: rule of tee-object ?

Jean wrote:
> "Sends input objects to two places."
> So, I am confused about what tee-object really do an what it was
> supposed to do ...


It sends input objects to _one_ other place (file or variable) in addition
to piping them through.

# send processes to file and console
gps | tee-object -file ps.txt

# send processes to variable and console
gps | tee-object -var ps

Because all input is always piped through you can archive the "-file
ps.txt -var ps" case with:

$ps = (gps | tee-object -file ps.txt)
# or
gps | tee-object -var ps > ps.txt

If want to output to variable and some other place, you can just
use -OutVariable with most cmdlets:

gps -ov ps > ps.txt


My System SpecsSystem Spec
Old 05-20-2006   #3 (permalink)
Alex K. Angelopoulos [MVP]


 
 

Re: rule of tee-object ?

The Parameters section is apparently buggy. It looks like it needs to be
broken down per-usage syntax.

"Jean" <repondre@groupe.svp> wrote in message
news:mn.a3b07d656a03e86a.49174@windows...
> By reading "help tee-object" it isn't clear for me about its intended
> rule(s).
>
> When we read :
>
> "Sends input objects to two places."
>
> and in EXAMPLE 1 description :
>
> "Since there is no *second* path listed, the result will be displayed in
> the console."
>
> and in EXAMPLE 2 description :
>
> " This example gets the list of processes *and* sends the result to a file
> and creates a variable, the value of which will be the list."
>
> we must think tee-object has the ability to do two things simulteanously.
>
> But it isn't.
>
> We could think there is a mistake in EXAMPLE 2
>
> Get-Process notepad | Tee-Object -Variable proc
>
> and try something like
>
> Get-Process notepad | Tee-Object -Variable proc -file
> C:\Test1\testfile2.txt
>
> ... but that doesn't work.
>
> Reading USAGE in help we see that there are two syntaxes : one
> with -FilePath and one with -Variable.
> Reading PARAMETERS in help we see that those two parameters are "parameter
> required".
> An it's as it works :
> tee-object works with -FilePath *or* -Variable but not with -FilePath
> *and* -Variable.
>
> So, I am confused about what tee-object really do an what it was supposed
> to do ...
>
> Regards,
>
> --
> Jean - JMST
> Belgium
>
>



My System SpecsSystem Spec
Old 05-20-2006   #4 (permalink)
Alex K. Angelopoulos [MVP]


 
 

Re: rule of tee-object ?

Actually it seems to me that Tee-Object could be replaced by Out-File if
Out-File supported -PassThru. Does it look like that to you, Jouko?

What Jean attempted with multiple files looks interesting as well. It would
be nice to make FilePath support a list.


"Jouko Kynsijärvi" <jouko.kynsijarvi@nospam.nospam> wrote in message
news:OxI6FtBfGHA.1320@TK2MSFTNGP04.phx.gbl...
> Jean wrote:
>> "Sends input objects to two places."
>> So, I am confused about what tee-object really do an what it was
>> supposed to do ...

>
> It sends input objects to _one_ other place (file or variable) in addition
> to piping them through.
>
> # send processes to file and console
> gps | tee-object -file ps.txt
>
> # send processes to variable and console
> gps | tee-object -var ps
>
> Because all input is always piped through you can archive the "-file
> ps.txt -var ps" case with:
>
> $ps = (gps | tee-object -file ps.txt)
> # or
> gps | tee-object -var ps > ps.txt
>
> If want to output to variable and some other place, you can just
> use -OutVariable with most cmdlets:
>
> gps -ov ps > ps.txt
>
>



My System SpecsSystem Spec
Old 05-20-2006   #5 (permalink)
Jouko Kynsijärvi


 
 

Re: rule of tee-object ?

Alex K. Angelopoulos [MVP] wrote:
> Actually it seems to me that Tee-Object could be replaced by Out-File
> if Out-File supported -PassThru. Does it look like that to you, Jouko?


Maybe. But this mostly a "more smaller cmdlets" vs "more arguments and fever
cmdlets" case.

> What Jean attempted with multiple files looks interesting as well. It
> would be nice to make FilePath support a list.


Imho, it would make sence to support multiple files and variables at the
same time.

Sure, you can always chain things:

gps | tee ps1.txt | tee ps2.txt | tee -var ps3 | tee -var ps4

But the most general solution would be to support "subpipelines" as script
blocks, something like:

gps | tee {out-file foo.txt},{export-csv foo.csv},{export-clixml
foo.xml},{set-varible foo}


My System SpecsSystem Spec
Old 05-20-2006   #6 (permalink)
Jean


 
 

Re: rule of tee-object ?

Thank you Jouko.

Regards,

--
Jean - JMST
Belgium


My System SpecsSystem Spec
Old 05-20-2006   #7 (permalink)
Jean


 
 

Re: rule of tee-object ?

> The Parameters section is apparently buggy. It looks like it needs to be
> broken down per-usage syntax.


I agree.

Example 1 and 2 descriptions are buggy too.
"Since there is no second path listed" in 1 and "and sends the result
to a file" in 2 should be removed.

Regards,

--
Jean - JMST
Belgium


My System SpecsSystem Spec
Old 05-21-2006   #8 (permalink)
Alex K. Angelopoulos [MVP]


 
 

Re: rule of tee-object ?

I like your way much better. Want to feature that?

"Jouko Kynsijärvi" <jouko.kynsijarvi@nospam.nospam> wrote in message
news:OrlnfLCfGHA.3996@TK2MSFTNGP04.phx.gbl...
> Alex K. Angelopoulos [MVP] wrote:
>> Actually it seems to me that Tee-Object could be replaced by Out-File
>> if Out-File supported -PassThru. Does it look like that to you, Jouko?

>
> Maybe. But this mostly a "more smaller cmdlets" vs "more arguments and
> fever cmdlets" case.
>
>> What Jean attempted with multiple files looks interesting as well. It
>> would be nice to make FilePath support a list.

>
> Imho, it would make sence to support multiple files and variables at the
> same time.
>
> Sure, you can always chain things:
>
> gps | tee ps1.txt | tee ps2.txt | tee -var ps3 | tee -var ps4
>
> But the most general solution would be to support "subpipelines" as script
> blocks, something like:
>
> gps | tee {out-file foo.txt},{export-csv foo.csv},{export-clixml
> foo.xml},{set-varible foo}
>
>



My System SpecsSystem Spec
Old 05-21-2006   #9 (permalink)
Jouko Kynsijärvi


 
 

Re: rule of tee-object ?

Alex K. Angelopoulos [MVP] wrote:
> I like your way much better. Want to feature that?


Submitted as Feedback ID 77962:
https://connect.microsoft.com/feedba...edbackID=77962

> "Jouko Kynsijärvi" <jouko.kynsijarvi@nospam.nospam> wrote in message
>> But the most general solution would be to support "subpipelines" as
>> script blocks, something like:
>>
>> gps | tee {out-file foo.txt},{export-csv foo.csv},{export-clixml
>> foo.xml},{set-varible foo}



My System SpecsSystem Spec
Old 05-21-2006   #10 (permalink)
Keith Hill [MVP]


 
 

Re: rule of tee-object ?


"Jouko Kynsijärvi" <jouko.kynsijarvi@nospam.nospam> wrote in message
news:OrlnfLCfGHA.3996@TK2MSFTNGP04.phx.gbl...
> But the most general solution would be to support "subpipelines" as script
> blocks, something like:
>
> gps | tee {out-file foo.txt},{export-csv foo.csv},{export-clixml
> foo.xml},{set-varible foo}
>


This would also allow me to use tee to append output:

gps s* | tee { out-file foo.log}
gps w* | tee { out-file foo.log -append }

And yes I've already file a suggestion that tee provide a way to append
rather than always overwrite.

--
Keith


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Inherit from usercontrol - Object not set to instance of an object .NET General
datalist -- Object reference not set to an instance of an object. .NET General
Testing object arrays using Compare-Object and -contains PowerShell
Adding canonical aliases for Compare-Object, Measure-Object, New-Object 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