A package closes prematurely with the for / f command

I have a batch file (in Windows XP with the extension activated) with the following line:

for /f %%s in ('type version.txt') do set VERSION=%%s

On some computers, it works just fine (as shown on this SO question ), but on others it kills cmd (the console window just closes)

Why?


Note: computers seem to have a similar configuration: XpSP2, the user has administrator privileges, there is no "shell" defined in HKEY_CURRENT_USER \ Software \ Microsoft \ Command Processor ...

+5
source share
5 answers

I got the first empirical answer:

for /f %%s in (version.txt) do ...

works fine on every computer.

, for /f , - dos, 'type filename'.

( , " " )

15 (?) ;-), :
'for/f' , . DOS?


: 3 (!), barlop , "for /f cmd?". :

COMSPEC SET + ENTER.
, , COMSPEC . System Variables, , , .

ss64, Andriy M , .

< <26 > 'dir' ( , ) COMSPEC, cmd.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\ComSpec=
%SystemRoot%\system32\cmd.exe
+4

, CMD.EXE /E: OFF, ( ).

script, , .

- , http://www.ss64.com/nt/setlocal.html

SETLOCAL ERRORLEVEL, . , , - .

, , , :

VERIFY errors 2>nul
SETLOCAL ENABLEEXTENSIONS
IF ERRORLEVEL 1 echo Unable to enable extensions

, " VERIFY" ERRORLEVEL 1, SETLOCAL reset ERRORLEVEL, (, script .com)

, SETLOCAL ENABLEEXTENSIONS .

+1

, , cmd , ?

0

, (set) for .

, (set) for , .

, "type filename".

"cmd/?"

0

... , ? MS , , .

for /F ["usebackqParsingKeywords"] {%% | %}variable in ("filenameset") do command [CommandLineOptions]

for /F ["usebackqParsingKeywords"] {%% | %}variable in ('LiteralString') do command [CommandLineOptions]

for /F ["usebackqParsingKeywords"] {%% | %}variable in (`command`) do command [CommandLineOptions]

, , .

for/F , filenameset ( , "filenameset" ). Filenameset , .

0

All Articles