S
S
Seli_one2021-10-18 13:30:38
cmd/bat
Seli_one, 2021-10-18 13:30:38

How to output the result of a cmd command to a variable?

Hello colleagues.
There is a batch file containing the following command:
net user %username% | findstr /C:"Password expires" >tmp.txt
But there is a task to output this result not to a temporary file, but to a variable.
Google found some solution, but it doesn't work:
FOR /F "delims=" %i IN ('net user %username% ^| findstr /C:"Password ends"') DO set var=%i
Either I'm wrong I see.
Help me to understand.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2021-10-18
@Seli_one

This is how it should work:

for  /f "delims=" %i IN ('net user %username% ^| findstr /C:"Действие пароля завершается" ') DO set var=%i

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question