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 - BUG: Redirecting function contents to a file truncates function lines at the width of the console

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


 
 

BUG: Redirecting function contents to a file truncates function lines at the width of the console

In my profile.ps1 file, I have various functions with line widths greater
than 80 columns. My console is 80 columns.

If I use the following:

get-content function:foo >filename

The function body will be written to the filename, but the lines will be
wrapped at the width of the console. This of course results in invalid code
when the end of a comment is on its own line, or a variable name gets cut
off in the middle.

I've had to do the following:

(get-content function:foo).ToString() >filename

Which works as expected.

I imagine there are probably other instances of the console formatting being
applied to things that are being sent to a text file.



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


 
 

Re: Redirecting function contents to a file truncates function lines at the width of the console

The redirector operator uses out-file underneath. Try this:

gc function:foo | out-file filename -width 120

There are other parameters on out-file that allow you to controls things
like encoding, appending, etc.

--
Keith

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


 
 

Re: Redirecting function contents to a file truncates function linesat the width of the console

Keith Hill [MVP] wrote:
> The redirector operator uses out-file underneath. Try this:
>
> gc function:foo | out-file filename -width 120
>
> There are other parameters on out-file that allow you to controls things
> like encoding, appending, etc.

Hmm, thanks, good to know.

But it shouldn't be wrapping lines in output files by default, I don't
think.

And how could I send the error stream to a file without it wrapping?
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
function to delete a function PowerShell
File.Exists Function .NET General
function return values, console output PowerShell
How to - named function in script 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