0

当我执行 PowerShell 脚本时,我遇到了一个非常奇怪的行为。我想运行该命令的子tf命令。该可执行文件通常用作控制台应用程序,但子命令tf resolve命令会显示一个我想查看的对话框。

一些 PowerShell Guru 可以解释一下,用例 1b 和 2b 中发生了什么?或者你有什么提示这里有什么问题吗?

备注:如果没有找到请根据你的安装修改VS版本。我正在使用 VS 2015、PowerShell 4、Windows 8.1。

用例 1a: 显示对话框(一切正常)

$tfCommand = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 14.0\Common7\IDE\tf.exe"
& $tfCommand resolve

用例 1b: 不显示对话框(WTF?!)

更改: STDOUT 保存在变量中

$tfCommand = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 14.0\Common7\IDE\tf.exe"
$someVariable = & $tfCommand resolve

用例 2a: 显示对话框(一切正常)

$tfCommand = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 14.0\Common7\IDE\tf.exe"

function callTfResolve($tfCommand) { 
   & $tfCommand resolve 
}

CallTfResolve $tfCommand

用例 2b: 不显示对话框(WTF?!)

更改:的返回值CallTfResolve保存在变量中

$tfCommand = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 14.0\Common7\IDE\tf.exe"

function callTfResolve($tfCommand) { 
   & $tfCommand resolve 
}

$someVariable = CallTfResolve $tfCommand
4

2 回答 2

1

尝试将/prompt添加到命令行。

使用对话框 UI 显示

$tfexe = "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\TF.exe"
$tfscollection = "http://tfs-isl01:8080/tfs/mepcollection"
$arglist = "workspaces /s:$tfscollection" 
Set-ExecutionPolicy Unrestricted
Start-Process $tfexe -ArgumentList $arglist   -RedirectStandardOutput C:\NewWS.log -RedirectStandardError c:\wserror.log -Wait
$arglist = "workspace /new /permission:Public /prompt"
Start-Process $tfexe -ArgumentList $arglist -RedirectStandardOutput C:\NewWS.log

不显示对话框 UI

$tfexe = "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\TF.exe"
$tfscollection = "http://tfs-isl01:8080/tfs/mepcollection"
$arglist = "workspaces /s:$tfscollection" 
Set-ExecutionPolicy Unrestricted
Start-Process $tfexe -ArgumentList $arglist   -RedirectStandardOutput C:\NewWS.log -RedirectStandardError c:\wserror.log -Wait
$arglist = "workspace /new /permission:Public"
Start-Process $tfexe -ArgumentList $arglist -RedirectStandardOutput C:\NewWS.log

感谢http://www.wintellect.com/devcenter/jrobbins/working-offline-with-tfs

希望这能解决你的问题

于 2016-05-29T11:32:42.350 回答
0

ProcessStartInfo因此,当我使用 $true 创建流程并将其设置RedirectStandardError为 $true时,看起来行为是相同的。

我觉得这个tf命令的执行很奇怪。类似于:“如果重定向流是 TTY,则抑制对话框,如果不显示它。”

我可能不得不在没有得到命令输出的情况下找到解决方案。

于 2016-03-04T12:49:04.770 回答