Discussion:
Write log file to stderr
(too old to reply)
m***@tempo.com
2017-01-29 00:45:17 UTC
Permalink
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
2017-01-29 02:36:24 UTC
Permalink
Post by m***@tempo.com
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.
$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.
Post by m***@tempo.com
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
m***@tempo.com
2017-02-13 22:08:01 UTC
Permalink
Post by Jürgen Exner
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.

Loading...