简体   繁体   English

在Powershell中使用参数运行TFS命令

[英]Running TFS commands with arguments in powershell

Hi I am trying to run the "tf get" command through powershell but i always get a unexpected token error when it reaches the arugments. 嗨,我正在尝试通过Powershell运行“ tf get”命令,但是当到达终端时,我总是会收到意外的令牌错误。

I was following the instructions from this post TFS commands in PowerShell script 我正在按照PowerShell脚本中此帖子TFS命令的说明进行操作

the line where the error is happening is 发生错误的行是

"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\tf.exe" @("get", $args[$i])

where $args[$i] is an argument being entered by the user, but the script stops executing after calling the tf.exe $ args [$ i]是用户输入的参数,但是脚本在调用tf.exe后停止执行

Could someone help me out here? 有人可以帮我吗? Thanks. 谢谢。

You can't execute a command in a string without using the call operator eg & . 不使用调用运算符(例如&就不能在字符串中执行命令。 In PowerShell a string evaluates to a string eg: 在PowerShell中,字符串的计算结果为字符串,例如:

C:\> "hello world"
hello world

You have to tell PowerShell that the string contains the name of a command using the call operator. 您必须使用调用运算符告诉PowerShell该字符串包含命令名称。

$tf = 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\tf.exe'
& $tf get $args[$i]

Note: when using & the string must contain just the name of the command. 注意:使用& ,字符串必须仅包含命令名称。 Arguments should be specified separately. 参数应单独指定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM