[ACCEPTED]-How to store the result of a command expression in a variable using bat scripts?-batch-file
Accepted answer
set cmd="dir /b "20??????" | find /c "2" "
FOR /F "tokens=*" %%i IN (' %cmd% ') DO SET X=%%i
0
(dir /b "20??????" | find /c "2")>>x.txt
set /p variable=<x.txt
That's all.
Of course, if you don't want 5 the file, just do this afterwards:
del x.txt
EDIT -- How 4 to make the filename unique:
@Mai: use this 3 to create a uniqe file name:
set timestamp=%date:.=%%time::=%
set timestamp=%timestamp:,=%
set timestamp=%timestamp:/=%
set timestamp=%timestamp:-=%
set filename=file%timestamp%.tmp
Add more replacements 2 if the date format of your system culture 1 has other characters inside
Here's a sample:
@echo off
set wildcard=C:\*.*
set count=0
FOR /F %%a in ('DIR /B %wildcard%') do set /A count=count+1
echo %count% files matching %wildcard%
set choice=
set /p choice=Press enter to continue ...
0
This is my code:
@echo off
set com=echo HI
::Start Of Code You Need
echo|%com%>>"%temp%\tmp.txt"
for /f "tokens=* delims=" %%x in (%temp%\tmp.txt) do (
set output=%%x
)
del /q %temp%\tmp.txt
::End Of Code You Need
echo This Is The Output:
echo %output%
pause>NUL
It takes the input from 1 com
and outputs from output
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.