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

stderr from external program to write-error

5 views
Skip to first unread message

wofat68

unread,
Sep 11, 2009, 6:18:36 AM9/11/09
to
Hi,

I have the following problem: my PS script calls an external program
(actually a template processor). The external program writes error
messages to stderr. I have verified this by redirecting output with
2>err.txt. When running the PS script, the error messages from the
external program are easily overlooked because they are obviously
written to the PS output pipeline rather than to the error pipeline.
To say it another way: I would like the error message from the
external program appear as red on black as if they written with Write-
Error.

I'm using PS only occasional and I wasn't able to find a solution or
even a "best practice" how to handle errors from external programs.

Any help?

Thanks a lot.

Marco Shaw [MVP]

unread,
Sep 11, 2009, 11:19:05 AM9/11/09
to
If you're stuck with PowerShell v1, I believe you are out of luck. If
you're considering v2, then check this as it may help:
http://www.nivot.org/2009/08/19/PowerShell20AConfigurableAndFlexibleScriptLoggerModule.aspx

Oisin mentioned he was planning to add even more features to the above.

Marco

"wofat68" <atlantic...@googlemail.com> wrote in message
news:b0b54f4f-23c1-4db2...@z24g2000yqb.googlegroups.com...

wofat68

unread,
Sep 11, 2009, 11:48:43 AM9/11/09
to
On Sep 11, 5:19 pm, "Marco Shaw [MVP]" <marco.shaw@NO_SPAMgmail.com>
wrote:

> If you're stuck with PowerShell v1, I believe you are out of luck.  If
> you're considering v2, then check this as it may help:http://www.nivot.org/2009/08/19/PowerShell20AConfigurableAndFlexibleS...

Indeed, I'm stuck with PS v1 for while. Thanks anyway.

My idea was to redirect stderr to a PS variable for later analysis and
output with Write-Error. I played around with Invoke-Expression and
the -ErrorVariable parameter. No success so far. I'm probably doing
something wrong here. Documentation is quite sparse. Is there at least
a way to catch stderr without redirecting to a temporary file? That
would be an enormous help.

Thanks.

0 new messages