base on the post SO: Executing command with FOR /F — “command not found”.
I tested the behaviour of ComSpec.
If you open a new cmd.exe window and try
Code: Select all
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. Alle Rechte vorbehalten.
C:\>set ComSpec=XXX
C:\>FOR /F %A in ('set APP') do @echo %A
Der Befehl "set test" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
C:\>set ComSpec=C:\windows\system32\cmd.exe
C:\>FOR /F %A in ('set APP') do @echo %A
Der Befehl "set test" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
Okay the first FOR /F fails as ComSpec is invalid, but why the second FOR fails too?
Next test in a fresh cmd.exe window
Code: Select all
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. Alle Rechte vorbehalten.
C:\>FOR /F %A in ('set App') do @echo %A
APPDATA=C:\Users\Jan
C:\>set ComSpec=XX
C:\>FOR /F %A in ('set App') do @echo %A
APPDATA=C:\Users\Jan
Wow , even the second FOR works!
It seems that ComSpec will be cached internally when it's used the first time.