Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Help with stderr from native console application

Reply
 
Old 03-29-2007   #1 (permalink)
Michael Lynch


 
 

Help with stderr from native console application

I’m trying to process the results of a native windows console application.
The application returns some xml in stdout if successful, or an error to
stderr if not. Ultimately, I would like a script that returns an [xml]
object, or a single error depending upon whether the console application
succeeded or not.

I have gotten as far as: [xml] [string]::join("`n", ( svn info --xml ))

Which works great if svn.exe succeeds, but not so great if it fails. If it
fails I get the following output:
svn: '.' is not a working copy
Cannot convert value "<?xml version="1.0" encoding="utf-8"?>
<info>" to type "System.Xml.XmlDocument". Error: "Unexpected end of file has
occurred. The following elements are not closed: info. Line 2, position 7."
At line:1 char:21
+ [xml] [string]::join( <<<< "`n", ( svn info --xml ))

The second error occurs because even when svn fails, it outputs invalid xml.
What I really want is a single error “svn: '.' is not a working copy”

I have tried varying combinations of $ErrorActionPreference, and
invoke-expression with –ErrorAction to no avail. I think the root of the
problem is that I don’t understand how stderr is handled in PowerShell.

Can anyone help?

Thanks,

- Michael


My System SpecsSystem Spec
Old 03-30-2007   #2 (permalink)
Keith Hill


 
 

Re: Help with stderr from native console application

"Michael Lynch" <adoptableCoho@community.nospam> wrote in message
news:C3A9689A-BDE7-4CAF-9B74-F7DF74160679@microsoft.com...
> I’m trying to process the results of a native windows console application.
> The application returns some xml in stdout if successful, or an error to
> stderr if not. Ultimately, I would like a script that returns an [xml]
> object, or a single error depending upon whether the console application
> succeeded or not.
>
> I have gotten as far as: [xml] [string]::join("`n", ( svn info --xml ))


Try this:

[xml] [string]::join("`n", ( svn info --xml 2>$null ))

or if you want to capture the errors

[xml] [string]::join("`n", ( svn info --xml 2>SvnStderr.txt ))

This will redirect stderr to somewhere else besides the regular output. You
can look at $LastExitCode to make sure that Svn worked that is, if the type
cast to XML doesn't already error.

--
Keith

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Console application Vista General
Console Application in .NET .NET General
Console Application in .NET .NET General
Unhandled Exception in Console Application .NET General
ImageList for Console Application .NET General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46