Question

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 )

Was it helpful?

Solution 2

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%

OTHER TIPS

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)

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top