如何将tfs命令行结果存储在局部变量中? [英] How to store tfs command line result in local variable ?

查看:77
本文介绍了如何将tfs命令行结果存储在局部变量中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..

我想在批处理文件中的变量中存储tf folderdiff命令。我想检查是否在tfs上修改了任何文件。我可以通过以下命令获得修改的文件数量,但是如果修改的文件数量大于0,我想检查一些操作。





tf folderdiff [sourcePath] targetPath / recursive / login:username,password / noprompt / view:different





如果有任何想法请分享。

解决方案

将命令的结果读入变量有点棘手。我更喜欢一种解决方法:将结果写入临时文件,然后将其内容读取到变量:

 echo 42> %TEMP%\ tmp.txt
set / p result =<%TEMP%\ tmp.txt
if%result%GTR 40 echo OK



编辑

临时文件是在临时文件夹中创建的。


在批处理文件中没有办法直接将命令的输出分配给变量,但是您将其写入临时文件,而不是使用 set / p 将该临时文件读入变量...

 [您的命令]> output.tmp 
set / p var< output.tmp


Hi..
I want to store tf folderdiff command in variable in batch file. I want to check if there is any files modified on tfs. I'm able to get number of modified files number by following command but i want to check do some operation if modified files number is greater than 0.


tf folderdiff [sourcePath] targetPath /recursive /login:username,password /noprompt /view:different


If have any idea please share.

解决方案

It's a bit tricky to read result of a command into a variable. I prefer a workaround: write the result to a temp file then read its content to a variable:

echo 42 > "%TEMP%\tmp.txt"
set /p result=<"%TEMP%\tmp.txt"
if %result% GTR 40 echo OK


Edit
Temp file is created in temp folder.


In batch files there is no way to directly assign the output of a command to a variable, but you write it to a temp file and than read that temp file into a variable using set /p...

[your command] > output.tmp
set /p var < output.tmp


这篇关于如何将tfs命令行结果存储在局部变量中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆