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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

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