![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||