2016-03-04 95 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

希望這將解決您的問題