Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts Windows 7 Forum Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Help with stderr from native console application

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 03-29-2007   #1 (permalink)
Michael Lynch
Guest


 

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
Guest


 

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
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Unhandled Exception in Console Application AG .NET General 10 04-10-2008 09:20 AM
ImageList for Console Application jp2msft .NET General 8 03-20-2008 05:19 PM
Creative Console Launcher 2.40.09 Application for X-Fi Series Cal Bear '66 Vista General 0 09-08-2007 07:20 AM
Creative Console Launcher 2.40.09 Application for X-Fi Series Cal Bear '66 Vista music pictures video 0 09-08-2007 07:20 AM
Application Compatibility SMS 2003 Admin Console Mario Vista General 0 03-30-2007 11:42 AM


Vistax64.com 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 2005-2008

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 47 48 49 50 51