Isolation of programs' output

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
BoQsc
Posts: 92
Joined: 30 Jun 2014 04:10

Isolation of programs' output

#1 Post by BoQsc » 11 Mar 2017 04:56

I want to convert single line programs' output into simple text and store it into a variable.

Where do I go wrong with this code below?

Code: Select all

for /f %%i in ('(echo ^| set /p="%var2%")') do set VAR=%%i

Summary of actions of above code:
  • With (echo ^| set /p="%var2%") I sanitize output
  • Then trying to place sanitized output into variable VAR
  • Getting error that giving hints of syntax error (That's my guess)

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Isolation of programs' output

#2 Post by aGerman » 11 Mar 2017 06:17

Where do I go wrong with this code below?

At least with not escaping the parentheses.

Code: Select all

@echo off &setlocal
set "var2=test"

for /f %%i in ('^(echo ^| set /p "=%var2%"^)') do set VAR=%%i

echo %VAR%
pause

Note that I also moved the equal sign into the pair of quotation marks. Otherwise you would have to escape it, too.

Steffen

Post Reply