How to capture the result of a command and store it in an MS-DOS variable in a batch file?

0

I'm developing a batch script to run in MS-DOS and I need to capture the output of an application running on a variable, which can be used during the execution of the .bat file. The command line that provides the desired result is:

C:\>youtube-dl -e https://www.youtube.com/watch?v=T084eSHL6P8

The above command, when run at the MS-DOS prompt, provides the following output:

"Youtube-dl for windows - Baixando canais inteiros do youtube."

In my file .bat I am using the following line to capture and store the result of executing the command:

set var=(youtube-dl -e https://www.youtube.com/watch?v=T084eSHL6P8)

The result is not expected, ie it displays exactly the string above, however, what is the correct way to assign the result of the command to a variable?

Thanks in advance for any help,

regards

Augusto Cesar

    
asked by anonymous 09.09.2018 / 17:44

1 answer

2

I've taken the example here: How to store the result of a command expression in a variable using bat scripts? > And I ran a test and it worked:

set c="youtube-dl -e https://www.youtube.com/watch?v=T084eSHL6P8"
for /f "tokens=*" %i in ( '%c%' ) do set xx=%i
echo %xx%
    
09.09.2018 / 18:15