For / f closes cmd command immediately

When I open cmd.exe and type this first line and press ENTER, it works fine. When I enter this other line and press ENTER, it closes immediately.

I can change ('a') to ('asdfgh') the same. or% q to% of the same problem.

The difference is that / f, for some reason FOR / F with ('......'), causes cmd.exe to close.

This happens on one of my systems and not on the other

C:\>for %q in ('a') do echo %q   <ENTER>

C:\>echo 'a'
'a'

C:\>for /f %q in ('a') do echo %q <ENTER>
+2
source share
3 answers

This guy seems to have successfully solved a very similar problem:

for / f closes cmd window immediately

COMSPEC, , , . Windows .

+4

"(", :

for %q in ('a') do (

"?". , ")"

0

"FOR" ( "FOR/?" ), , "/F" :

FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ("string") DO command [command-parameters]
FOR /F ["options"] %variable IN ('command') DO command [command-parameters]

, ... , - FOR.

, 'a'/ , ?

You should use the '/ F' flag if you specifically want the behavior that '/ F' supplies.

0
source

All Articles