捕获用于流量控制的非标准 Powershell CmdLet 输出 [英] Capturing Non-Standard Powershell CmdLet Output for Flow Control

查看:24
本文介绍了捕获用于流量控制的非标准 Powershell CmdLet 输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前正在尝试使用 MS 发布的Team Foundation Server Power Tools"包中的 cmdlet 构建脚本.

Currently trying to build a script utilizing cmdlets from the MS released "Team Foundation Server Power Tools" package.

我正在尝试根据Update-TfsWorkspace"cmdlet 的成功或失败来处理命令逻辑,但是我似乎无法从调用中获取返回码,也无法捕获使用 Out-String 输出.我使用的是 Powershell v1.

I'm attempting to flow command logic from the success or failure of the "Update-TfsWorkspace" cmdlet however I can't seem get a return code out of the call nor can I capture the output using Out-String. I'm using Powershell v1.

update-tfsworkspace "C:\doesnotexist\" -recurse -version T

产生无法确定工作区"的消息.这是我试图捕捉的错误.

Yields a message of "Unable to determine the workspace." which is the error I'm trying to catch.

$ret = update-tfsworkspace "C:\doesnotexist\" -recurse -version T

预计会给我一个 $true/$false 指示成功/失败但不起作用.

Is expected to give me a $true/$false indicating success/fail but doesn't work.

update-tfsworkspace "C:\doesnotexist\" -recurse -version T | Out-Null

预计会阻止 cmdlet 写入消息,但不起作用.

Is expected to prevent the cmdlet from writing the message but doesn't work.

trap{echo "fail"}
update-tfsworkspace $workspace_path -recurse -version T

预计会捕获错误并写入失败"但不起作用.

Is expected to catch an error and write "fail" but doesn't work.

$msg = update-tfsworkspace $workspace_path -recurse -version T | Out-String

预期会使用主机输出填充 $msg 变量,但不起作用.

Is expected to populate a $msg variable with the host output but doesn't work.

我在这里完全没有想法.帮助将不胜感激!

I'm totally out of ideas here. Help would be appreciated!

推荐答案

Little hacky,但由于我没有 TFS 来尝试解决其他问题,请查看 这个有帮助.

Little hacky, but since I don't have TFS to try to figure something else out, see if this helps.

这篇关于捕获用于流量控制的非标准 Powershell CmdLet 输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆