I need to store the output of a command line in a variable. How can I do this?
|
Provided a simple batch file
You can set the output into a variable with the following command line:
Used on the command line like this:
Should you want to use the |
|||||
|
|
You can pipe the command into something like:
What you see above sends the output to a named file. If file does not exist, it creates one. Overwrites existing file And you can also do this:
This appends the output to contents of a named file or creates a file if none exists See also here: Using command redirection operators |
|||||||
|
|
This is how I do this:
If result.txt has more than 1 line, only the top line of the file is used for %DATA%. You could also make result.txt into a variable itself, such as %OUTPUT%. |
|||
|
|