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

Asked

Viewed 1,380 times

1

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

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

The above command, when executed at the MS-DOS prompt, provides the following result:

"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 as expected, i.e., it displays exactly the above string, however, what is the correct way to assign the result of the command to a variable?

Thanking in advance any help,

yours sincerely

Augusto Cesar

1 answer

3

  • It worked! The modifications I made were the following (can be used for others): @echo off cls echo Wait while the script captures the name of the video... set c="youtube-dl -e https://www.youtube.com/watch?v=T084eSHL6P8" for /f "tokens=*"%i in ('%c%') set xx=%i echo Video name eh: %xx% pause

Browser other questions tagged

You are not signed in. Login or sign up in order to post.