I got a first empiric answer:
for /f %%s in (version.txt) do ...
works just fine, on every computer.
It seems for /f
works 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 /f
closes cmd prompt immediately?". His conclusion was:
COMSPEC
did get listed when doing SET
+ENTER.
So, I opened the environment variables window, and saw COMSPEC
was not listed under user or system variables. I added it to System Variables, started a command prompt, and it seems to work fine.
This thread on ss64 forum, mentioned by Andriy M in his answer to barlop's question, contains the details.
The shelling out in the "for
" loop to complete 'dir
' (or whatever command you've asked to complete) requires ComSpec
to be set in order to reload the cmd
window.
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\ComSpec=
%SystemRoot%\system32\cmd.exe