I need to store the output of a command line in a variable. How can I do this?
Windows – How to Store Output of Command in Batch File
batch-filecommand-line-interfacewindows
Related Topic
- Windows – Does Windows Have a Built-in ZIP Command for Command Line?
- Windows – What’s the command-line utility in Windows to do a reverse DNS look-up
- Windows – Get folder and file names and store it in a variable in windows
- Windows Batch File – How to Sleep in a Batch File
- Windows – How to Extract command-line output into a Variable
- Windows – Store PS command output to variable and Invoke-Command
Best Answer
Provided a simple batch file
test.cmd
with the contents: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
FOR
within a batch file, rather than command line, you need to change%a
to%%a
.