【问题标题】:PowerShell suppresses TF command UI, when output is captured in a variable当在变量中捕获输出时,PowerShell 会抑制 TF 命令 UI
【发布时间】:2016-06-18 01:41:49
【问题描述】:

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

能否请 PowerShell 大师解释一下,用例 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

【问题讨论】:

    标签: powershell tfs tf-cli


    【解决方案1】:

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

    我觉得tf命令的实现很奇怪。就像是: “如果重定向流是 TTY 则抑制对话框,如果不显示它。”

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

    【讨论】:

      【解决方案2】:

      尝试将 /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

      希望这能解决您的问题

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-25
        • 2018-05-04
        • 2022-01-15
        • 1970-01-01
        • 1970-01-01
        • 2012-06-02
        相关资源
        最近更新 更多