简体   繁体   English

FOR / f之后批处理文件不继续

[英]Batch file does not continue after FOR /f

The batch file below runs through the :RUNRULES section, executes the DO for every file in folder and after the loop executes things get funky. 下面的批处理文件通过:RUNRULES节运行,对文件夹中的每个文件执行DO,然后在循环执行后变得很时髦。 The IF never gets executed. IF永远不会执行。

The ECHO is executed, but the echo command is not echoed, as if ECHO OFF was active. 执行了ECHO,但未回显echo命令,就像ECHO OFF处于活动状态一样。 The IF is also not echoed. IF也没有回显。

::@ECHO OFF
SETLOCAL ENABLEEXTENSIONS

SET S1=Server1
SET S2=Server2
SET DATABASE=DbName
SET SCRIPT=folder\sqlscript.sql

:S1
ECHO Running rules in S1
SET SERVER=%S1%
GOTO RUNRULES

:S2
ECHO Running rules in S2
SET SERVER=%S2%
GOTO RUNRULES

:RUNRULES
SET OUTPUTFILE=%SERVER%_folder.csv
COPY NUL %OUTPUTFILE% 
FOR /f %%f IN ('dir /b /on folder') DO (
    IF EXIST results.csv DEL /Q results.csv 
    CALL RunRule "%SERVER%" "%DATABASE%" "folder\%%f" "results.csv"
    TYPE results.csv >>%OUTPUTFILE%
)

ECHO Past the FOR loop
IF %SERVER%==%S1% GOTO S2

The RunRule is a batch file that includes an ECHO OFF and sets the environment variable SERVER to another value, adding quotes to the value of SERVER. RunRule是一个批处理文件,其中包含ECHO OFF并将环境变量SERVER设置为另一个值,并在SERVER的值上加上引号。 The IF compares the new value of SERVER to the value it was originally set to and does not execute because they are not equal. IF将SERVER的新值与其最初设置的值进行比较,并且由于它们不相等而无法执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM