header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Write-Host/Write-Verbose Output LineFeed in Transcript
Last Post 27 Jan 2012 03:48 AM by Knurmia. 1 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
0ptikGhostUser is Offline
Basic Member
Basic Member
Posts:296
Avatar

--
04 May 2010 03:17 PM

    I'm using Start-Transcript and Stop-Transcript in PowerShell v2.0 to provide basic logging to my collection of scripts. I noticed that each line of text produced by Write-Host and Write-Verbose (the other write cmdlets might be equally affected but I didn't check) have only a LineFeed ("`n") at the end rather than CarriageReturnLineFeed ("`r`n") as expected. This can be easily reproduced by running the following commands:

    Start-Transcript Test.log Write-Verbose "Hello, World!" -verbose Write-Host "Goodbye, World..." Stop-Transcript

    I first noticed this because notepad doesn't handle the bare LineFeed correctly and all my logging appeared on a single line. I used notepad++ to show all characters and quickly noticed the cause. You can artificially inject the CarriageReturns manually:

    Start-Transcript Test.log Write-Verbose "Hello, World!`r" -verbose Write-Host "Goodbye, World...`r" Stop-Transcript

    I'd rather not add "`r" to each and all logging lines if I can avoid it. Is there any way to mitigate this without adding "`r" at the end of each logging line?

    KnurmiaUser is Offline
    New Member
    New Member
    Posts:1
    Avatar

    --
    27 Jan 2012 03:48 AM
    I know this is an old post, but I though I'd share a way I was able to fix the problem. I'm trying to resolve the issue for quite some time and this is what I came up.
    
    Start-Transcript Test.log Write-Verbose "Hello, World!" -verbose Write-Host "Goodbye, World..." Stop-Transcript
    $a = Get-Content Test.log
    $a > Test.log
     
     
    It's not pretty, but now I'm able to open the logs with Notepad!

    Kristofer
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer