Click here to Skip to main content
14,969,910 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

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.
   
v3
Comments
SachinSutar 12-Feb-15 3:52am
   
Access is denied message displayed.
Is need any permission for it ?
Tomas Takac 12-Feb-15 7:32am
   
It's probably because you don't have the right to write to the current folder. I update the solution so the file is created in temp folder, this should do the trick.
SachinSutar 12-Feb-15 20:07pm
   
Thanks.. It works.
now i want to check some fixed string is exist in that variable or not so i tried

echo %result%|find "%fixValue%" >nul
if %errorlevel% == 0 (echo yes) else (echo no)

but it always return error level 1 even if string is present in result.
have you idea how to do that ?.
Tomas Takac 13-Feb-15 2:14am
   
The way you check for errorlevel is wrong, try this:
if errorlevel 1 (echo no) else (echo yes)
It means "if errorlevel >= 1 ..."
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
   
Comments
SachinSutar 12-Feb-15 3:38am
   
I tried that but it gives "Access is denied" message.
Is it need any permission ?
Kornfeld Eliyahu Peter 12-Feb-15 4:08am
   
Maybe to write the file?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900