2016-03-04 90 views
0

当我执行PowerShell脚本时,我经历了一个非常奇怪的行为。我想运行tf命令的子命令。该可执行文件通常用作控制台应用程序,但子命令tf resolve命令显示一个对话框,我想查看它。当输出捕获到变量中时,PowerShell禁止TF命令UI

请问一些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 

回答

0

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

我觉得执行tf的命令很奇怪。例如: “如果重定向流是TTY,则禁止该对话框,如果不显示它。”

我可能必须找到一个解决方案,而不会得到命令的输出。

0

尝试将/提示添加到命令行。

显示与对话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

希望这将解决您的问题