View Single Post
Old 11-28-2007   #6 (permalink)
Keith Hill [MVP]


 
 

Re: native command messages/errors

"Marco Shaw [MVP]" <marco.shaw@_NO_SPAM_gmail.com> wrote in message
news:#5wKAybMIHA.4476@xxxxxx
Quote:

>
Quote:

>> 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"
>
>
> Try moving "> c:\test.txt" outside of the quotes.
And combine with Jon's suggestion:

& "$TFExecutablePath\tf.exe" workspace /delete $Name
/s:$TeamFoundationServerUrl /i 2>&1 > c:\test.txt

This is something I do all the time with my build scripts (we use TFS also).
You might also find this useful

#--------------------------------------------------------------------
# Helper function to deal with legacy exe exit codes
#--------------------------------------------------------------------
function CheckLastExitCode {
param ([int[]]$successCodes = @(0), [scriptblock]$script)

$Scriptname = $MyInvocation.Scriptname
$ScriptLine = $MyInvocation.ScriptLineNumber - 2
$failureMessage = (gc $Scriptname)[$ScriptLine]

if ($successCodes -notcontains $LastExitCode) {
if ($script) {
"Executing cleanup script: $script"
&$script
}
throw "EXE EXITED WITH CODE ${LastExitCode}: $failureMessage"
}
}

The one thing I like about this WRT TF.exe is that TF.exe returns a partial
success code (1) so you can specify an array of "success" codes in this
function as well as a cleanup function if it fails e.g.:

tf.exe ....
CheckLastExitCode 0,1 { tf.exe undo $path /r /i }

--
Keith

My System SpecsSystem Spec