Why does looping through chcp.com give an error when running it, storing the output, and looping through that does not?

Looping through C:\Windows\System32\chcp.com works but gives an error. On the other hand, merely executing chcp.com does not. To wit:

C:\Windows\System32>for /F "tokens=2 delims=:." %a in ('"%SystemRoot%\System32\chcp.com"') do (echo %a)


The system cannot find the path specified.

C:\Windows\System32>(echo  437 )

On the other hand,



Active code page: 437

(looping through "Active code page: 437" produces the expected result).

I've read relate a question on how FOR works, and then read the related info, FOR /? and this. I'm posting on SO rather than SU since I think it's about how FOR loops work in cmd.exe and batch files, but it could be about the internals of chcp.com.

That's the MWE, but the larger context is python virtual environments. The activate.bat files use this loop to switch the code page to unicode. activate.bat appears to work in all regards, but some IDEs (VSCode) trip over the error when setting up an Jupyter interactive window and fail. Would love a larger solution so that creating a virtual environment did not run into this problem in general.