Reputation: 11
I'm writing a simple batch file where I'm using the find /C
command and want to set the result of that to be a value for a variable.
More generally, is there a way to get the previous lines result to store as a variable? I will provide an example to explain what I mean here as there is some confusion.
EX1. Find /C "abcd" text.txt
This outputs a number, this number is what I mean by "previous line's result."
EX2. time /T
This outputs the current system time, the time is what I mean by "previous line's result."
Upvotes: 0
Views: 3876
Reputation: 14340
You can store the output of any command by using a for
loop with the /F
option.
for /F "delims=" %%A in ('command') do set your_variable=%%A
Note the single quotes ('
) surrounding the command; this tells batch that it's a command and not a string or a file.
Upvotes: 2