I have a batch file (in windows XP, with command extension activated) with the following line:
for /f %%s in ('type version.txt') do set VERSION=%%s
On some computer, it works just fine (as illustrated by this SO question), but on other it kills cmd (the console window just closes)
Why ?
Note: the computers seem to have a similar configuration: XpSP2, the user has administrative right, no ‘Command processor’ defined in HKEY_CURRENT_USER\Software\Microsoft\Command Processor…
I got a first empiric answer:
works just fine, on every computer.
It seems
for /fworks with a filename, not with any dos command like ‘type filename’.However, it is not true for all my client’s computer (on some, the ‘type filename’ works fine)
If you want 15 (easy ?) points ;-), you can leave an answer to the question:
why ‘for /f’ sometime does not work with anything else than a file name. And why it just closes the DOS session ?
Edit: 3 years later(!), barlop faced a similar situation, detailed in the question ‘
for /fcloses cmd prompt immediately?‘. His conclusion was:This thread on ss64 forum, mentioned by Andriy M in his answer to barlop’s question, contains the details.