简体   繁体   English

循环进入Windows批处理文件

[英]Loop in a Windows Batch File

I'm trying to create the following batch file: 我正在尝试创建以下批处理文件:

@echo off

set "list=AICourse AIStudent Teacher"
set Server="localhost"
set Username="user"
set Password="()$rDCg3st@0"

    for %%n in (%list%) do (

        Set File=c:\temp\%%n.bcp
        Set Log=c:\temp\%%n.log_exp

        ECHO Begin BCP...: %TIME% 
        ECHO waiting...

        bcp Database.dbo.%%n OUT %File% -o %Log% -S%Server% -U%Username% -P%Password% -c

        ECHO End BCP..: %TIME% 
        ECHO Log in file %Log%

    )  

However, when I try to iterate through the array, only returns the last result. 但是,当我尝试遍历数组时,仅返回最后一个结果。 How can I iterate then? 那我该如何迭代呢?

Add this at the top of your script: 在脚本顶部添加以下内容:

SETLOCAL ENABLEDELAYEDEXPANSION

And, then change all the %Log% instances to !Log! 然后,将所有%Log%实例更改为!Log! and %File% instances to !File! %File%实例到!File! .

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

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