Jump to content

Direct output to variable in batch file


Recommended Posts

Posted

I'm wondering, if in a batch file it's possible to direct the stdout into a variable ? To be more sepcific, I want to save the output of the follwoing command to a variable:

reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v desktop

I found a solution to this, which first saves the information to a textfile and then reads the information from there. But I've got the impression, that it's possible to do this more direct.


Posted

Is this what you mean?

@echo off
setlocal enableextensions
for /f "tokens=*" %%a in (
 'reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v desktop'
) do (
 set myvar=%%a
)
echo/%%myvar%%=%myvar%
pause
endlocal
goto :eof

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...