当我执行 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