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 - FEATURE REQUEST: redirecting output to non-file objects

Reply
 
Old 08-11-2006   #1 (permalink)
Adam Milazzo [MSFT]


 
 

FEATURE REQUEST: redirecting output to non-file objects

It would be nice to be able to redirect output to objects that are not
files.

For instance:

$x = new-object Collections.ArrayList
doSomething >$x # collect items in ArrayList

or

$x = new-object Text.StringBuilder
doSomething >$x # collect items in a stringbuilder rather than a text file

You might say that I should simply write a function:

function toStringBuilder($sb)
{ begin { $local:sb = new-object Text.StringBuilder }
process { $sb.Append([string]$_) }
end { return $sb }
}

and do:

$sb = doSomething | toStringBuilder

But this does not work consistently. What if I want to send the ERROR stream
to it?

Redirection would handle it:

$x = new-object Text.StringBuilder
doSomething 2>$x # send errors to $x

A function would not, right?



My System SpecsSystem Spec
Old 08-11-2006   #2 (permalink)
Keith Hill [MVP]


 
 

Re: FEATURE REQUEST: redirecting output to non-file objects

"Adam Milazzo [MSFT]" <adamm@san.rr.com> wrote in message
news:Oyyji5avGHA.976@TK2MSFTNGP05.phx.gbl...
> It would be nice to be able to redirect output to objects that are not
> files.


Interesting idea but I think the problem you run into is that the shell
won't know which object member to use to append the pipeline object. I
guess the team could use a configuration file like they do for
type/formatting data. Still not sure if that is how I would expect the
system to work.

--
Keith

My System SpecsSystem Spec
Old 08-12-2006   #3 (permalink)
Adam Milazzo [MSFT]


 
 

Re: FEATURE REQUEST: redirecting output to non-file objects

Keith Hill [MVP] wrote:
> "Adam Milazzo [MSFT]" <adamm@san.rr.com> wrote in message
> news:Oyyji5avGHA.976@TK2MSFTNGP05.phx.gbl...
>> It would be nice to be able to redirect output to objects that are not
>> files.

>
> Interesting idea but I think the problem you run into is that the shell
> won't know which object member to use to append the pipeline object. I
> guess the team could use a configuration file like they do for
> type/formatting data. Still not sure if that is how I would expect the
> system to work.


Yeah. Well, they could use the IList interface to work with any object
that supported it. That would take care of ArrayList and many other
collections.

I don't think this is such a great feature all by itself, but it'd be
useful in conjunction with the ability to background tasks (since they
couldn't output to the console, and outputting to a text file loses
information).

% longRunningTask >$list &
[1]+ longRunningTask (running)

% go about other work...

[1]- longRunningTask (complete)

% $list # get my results
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Standard output redirecting PowerShell
Redirecting output to log file PowerShell
Redirecting Output in Powershell PowerShell
redirecting file output to .exe PowerShell
Many null characters in output when redirecting third party tool to a file 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