Windows Batch help in setting a variable from command output

Viewed 43940

I need to run a simple find command and redirect the output to a variable in a Windows Batch File.

I have tried this:

set file=ls|find ".txt"
echo %file%

But it does not work.

If I run this command it works without problems:

set file=test.txt
echo %file%  

So obviously my command output is not being set to my variable. Can anyone help? Thanks

8 Answers

I just find out how to use commands with pipes in it, here's my command (that extracts the head revision of an svn repo) :

SET SVN_INFO_CMD=svn info http://mySvnRepo/MyProjects
FOR /f "tokens=1 delims=" %%i IN ('%SVN_INFO_CMD% ^| find "Revision"') DO echo %%i
Related