Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Write log file to stderr

17 views
Skip to first unread message

mic...@tempo.com

unread,
Jan 28, 2017, 7:48:22 PM1/28/17
to
I'm running a powershell script viaa TFS and want to write a log file to
stderr. I've tried using write-error but all the line feeds are removed
when writing and the result is difficult to read.

What I'm doing is:

$c=Get-Content logfile.txt
Write-Error "$c"


But this writes everything on one line and when this gets back to TFS
it's shown as one line in the browser window with a large horizontal
scroll bar and it's not readable.

Is there a better way to write a file to standard error so that it
retains it's line breaks?

Jürgen Exner

unread,
Jan 28, 2017, 9:36:34 PM1/28/17
to
On Sun, 29 Jan 2017 00:45:17 +0000, "mic...@tempo.com"
<mic...@tempo.com> wrote in microsoft.public.windows.powershell:

>I'm running a powershell script viaa TFS and want to write a log file to
>stderr. I've tried using write-error but all the line feeds are removed
>when writing and the result is difficult to read.
>
>What I'm doing is:
>
>$c=Get-Content logfile.txt
>Write-Error "$c"
>
>But this writes everything on one line [...]

Yes. That is what happens when you stringify an array.

>Is there a better way to write a file to standard error so that it
>retains it's line breaks?

write-error never sees the line breaks. You are removing them beforehand
by stringifying $c. Just don't do that.

Just see the differnce in output between
$c
"$c"

jue

mic...@tempo.com

unread,
Feb 13, 2017, 5:08:10 PM2/13/17
to

> write-error never sees the line breaks. You are removing them beforehand
> by stringifying $c. Just don't do that.
>
> Just see the differnce in output between
> $c
> "$c"
>
> jue
>
A belated thank you.
0 new messages