0

I am unable to set a variable value inside for loop.

@echo off
SET PID=CREE6-GGGG8-FFFF6-SSSS9-DDDD5
FOR %%x in (%PID:-= %) do (
echo %%x
SET v=(echo %%x| convert_2_scancode.py)
echo %v%
)

Expected o/p CREE6 12 92 2e 23.......... (converted scan code of CREE6 )

3 Answers 3

1

For one thing... you are echoing the 'Load Time' value of the variable v. To see the 'Run Time' value within a FOR/IF construct or within parens you need to add this line (2nd line of your program).

setlocal enabledelayedexpansion

and then change your echo %v% to

echo !v!

Then there is the next problem. What are you attempting to do with

SET v=(echo %%x| convert_2_scancode.py)

Sign up to request clarification or add additional context in comments.

Comments

0

I'd try

@echo off
SET PID=CREE6-GGGG8-FFFF6-SSSS9-DDDD5
FOR %%x in (%PID:-= %) do (
echo %%x
for /f Delims=" %%v in ('echo %%x^|convert_2_scancode.py') do set v=%%v
)
echo %v%

Comments

0

As I don't have "convert_2_scancode.py", I wrote a little "emulator" instead

C:\Users\Stephan\102>type t.bat
@echo off
SET PID=CREE6-GGGG8-FFFF6-SSSS9-DDDD5
set pid=%PID:-= %
for /f "tokens=* delims=" %%x in ('convert_2_scancode.bat %pid%') do set "v=%%x"
echo %v%
------------------
C:\Users\Stephan\102>type convert_2_scancode.bat
@echo converted scancode from %*
------------------
C:\Users\Stephan\102>t
converted scancode from CREE6 GGGG8 FFFF6 SSSS9 DDDD5

C:\Users\Stephan\102>

1 Comment

Link to python file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.