0

I experienced a very weird behavior when I execute a PowerShell script. I want to run a sub-command of the tf command. This executable usually works as a console application, but the sub-command tf resolve command displays a dialog, which I want to see.

Can some PowerShell Guru please explain me, what's going on in Use case 1b & 2b? Or do you have a hint what's the problem here?

Remarks: Please modify the VS version according to your installation, if it is not found. I'm using VS 2015, PowerShell 4, Windows 8.1.

Use case 1a: Dialog is displayed (Everything is okay)

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

Use case 1b: Dialog is NOT displayed (WTF?!)

Changes: The STDOUT is saved in a variable

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

Use case 2a: Dialog is displayed (Everything is okay)

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

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

CallTfResolve $tfCommand

Use case 2b: Dialog is NOT displayed (WTF?!)

Changes: Return value of CallTfResolve is saved in a variable

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

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

$someVariable = CallTfResolve $tfCommand
Marcell Spies
  • 331
  • 3
  • 8

2 Answers2

1

Try adding the /prompt to command line.

Display with Dialog 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

Not displaying Dialog 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

thanks to http://www.wintellect.com/devcenter/jrobbins/working-offline-with-tfs

Hope this will solve your problem

galsi
  • 421
  • 1
  • 6
  • 19
0

So, it looks like that the behavior is the same, when I create the process with ProcessStartInfo and set RedirectStandardError to $true.

I think the implementation of the tf command is very strange. Something like: "If the redirect stream is a TTY then supress the dialog, if not display it."

I might have to find a solution without getting the output of the command.

Marcell Spies
  • 331
  • 3
  • 8