View Single Post
Old 11-28-2007   #2 (permalink)
Jon


 
 

Re: native command messages/errors


"Joey" <Joey@xxxxxx> wrote in message
news:0D0A70B5-E0CC-4EE7-B7C4-01439B978F16@xxxxxx
Quote:

> How do I get the verbose messages/errors displayed by native command calls
> back into a variable inside of powershell or at least to show up in the
> output? At the moment the closest thing I can find is the $lastexitcode
> variable which is good for determining if an error occurred but doesn't
> help
> in ascertaining the exact error message of a native command. The $error
> object contains nothing when a native command fails. I want to convert my
> processes over to powershell but without the ability to display exact
> error
> messages from native commands the benefits will not outweigh the hassles
> of
> trying to debug the scripts because the errors are not shown!
>
> Is there a way to “pipe” the native command call to a text file and then
> read that back into powershell after the command finishes? I tried to do
> this
> but the DOS pipe “>” didn’t work for whatever reason.
>
> E.g.
> & "$TFExecutablePath\.\tf.exe workspace /delete $Name
> /s:$TeamFoundationServerUrl /noprompt > c:\test.txt"
>



You can use 2> to pipe error messages to a file, and the Get-Content cmdlet
to read them back again eg

xcopy nosuchfileA fileB 2>errors.txt
$anyerrors = Get-Content errors.txt
$anyerrors

--
Jon


My System SpecsSystem Spec