简体   繁体   中英

How to handle tf.exe errors in PowerShell script

I have a PowerShell script that run tf.exe commands.

$tfExe = {C:\path\to\tf.exe}
& $tfExe checkout / checkin etc.

If I try to run checkin command to file that not changed I got an error:

The following changes were not checked in because the item were not modified.

Undoing edit: {C:\\path\\to\\file}

The problem is, I run the script within a TFS build, and the build fail with an error:

[error] There are no remaining changes to check in.

But this is not a real error, if there is no changes so don't do check in, this is good behavior for me.

How can I handle the tf.exe errors?

I tried with try catch but is not worked, altough there is an error the try block is excuted and not the catch .

I tried also with a variable get the output $test = & $tfExe checkin ... and still get an error (and the variable is empty).

PowerShell doesn't understand error from native executables. You have to parse through the output to take decision. You can redirect the error stream to output stream.

$Output = tf.exe … 2>&1

$Output.exception.message -match 'There are no remaining'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM