for /f closes cmd prompt immediately

前端 未结 3 583
生来不讨喜
生来不讨喜 2021-01-22 02:27

When I open cmd.exe and type that first line and push ENTER, it works fine. When I input that other line and push ENTER, it closes immediately.

I can change (\'a\') to (

3条回答
  •  一向
    一向 (楼主)
    2021-01-22 02:57

    Looking at the help for 'FOR' ('FOR /?'), you can see that the '/F' option is for parsing file input and has the following options:

    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]
    

    Note that last entry... a single-quoted value is treated as a command to run, and the output of that command is what 'FOR' is parsing.

    Perhaps you have an 'a' command/executable on one machine, but not on the other?

    You should only be using the '/F' flag if you specifically want the behavior that '/F' supplies.

提交回复
热议问题