Windows Vista Forums

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


    Adam Milazzo Guest

    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

  2. #2


    Keith Hill [MVP] Guest

    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

  3. #3


    Adam Milazzo [MSFT] Guest

    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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
File.Exists Function Smurfman-MSDN .NET General 4 27 Mar 2009
I'd like to edit a function's source file RickB PowerShell 3 15 Oct 2008
function return values, console output =?Utf-8?B?ZnV6enkzMzM=?= PowerShell 3 22 Aug 2006
How to - named function in script file Thomy Kay PowerShell 3 19 Aug 2006
Odd-width lines draw incorrectly (WPF Feb CTP) Mike Strobel Avalon 1 19 May 2006