我有 .bat 文件。看起来像下一个
....many commands1
ftp -i -s:copy.txt
...many commands2
copy.txt 包含下一个命令
open ...
login
password
get file
bye
当我执行我的 .bat 文件时,它接下来会起作用
many commands1
ftp commands
但是许多命令2仍然没有执行。
听起来您的一个command2
命令可能正在调用(启动)批处理文件而不使用该CALL
命令。(底部有两张流程图,解释了使用和不使用CALL
的后果。)请参阅**使用和不使用的后果CALL
。
如果我最初的预感不正确,您需要开始采取措施来调试您的批处理文件。
注释掉任何@ECHO OFF
语句并将一些PAUSE
甚至ECHO
语句放入您的批处理文件中。这将帮助您找到错误。CALL
另外,请记住,如果您希望代码执行批处理文件,则需要使用该命令,然后在执行CALL
完CALL
ed 批处理文件后继续执行 ing 批处理文件。另外,请注意,如果您CALL
的任何批处理文件包含ECHO OFF
语句,即使在控制权返回到ing 文件后,该语句ECHO OFF
也会继续执行。CALL
例如:
:: For debugging porpuses we leave `ECHO` in it's default `ON` state
REM @echo off
:: Execute your leading commands:
commands1
:: If you prefer, because you know that your problem comes after this point;
:: You can, if you want, leave the leading `ECHO OFF` command alone, and
:: instead, put an `ECHO ON` statement here:
echo on
ftp -i -s:copy.txt
ECHO Back from FTPing...
pause
:: Calling command2.1.exe
command2.1.exe
echo Back from command2.1.exe
pause
:: Calling command2.2.bat
CALL command2.2.bat
:: Since Command2.2.bat contains an ECHO OFF statement
:: we'll turn `ECHO` back on again for debugging purposes.
ECHO ON
echo Back from command2.2.bat
pause
CALL
。假设这两个批处理文件:
RUN.BAT
@ECHO OFF
ECHO Starting: RUN.BAT
(Misc commands)
:: 'Calling' SECOND.BAT without useing `CALL`
SECOND.BATCH
:: Back from SECOND.BAT
ECHO Back from second.bat
SECOND.BAT
@echo off
ECHO Running: SECOND.BAT
没有语句的执行流程CALL
将像这样移动:
C:\> RUN.BAT<kbd>ENTER</kbd>
|
\|/
v
@echo off
echo Running
(misc commands)
|
\|/
v
SECOND.BAT ----> @echo off
echo Running Seond.bat
(misc commands)
|
\|/
v
END
但是如果你将文件中SECOND.BAT
的 line更改为,则执行流程将如下所示:RUN.BAT
CALL SECOND.BAT
C:\> RUN.BAT<kbd>ENTER</kbd>
|
\|/
v
@echo off
echo Running
(misc commands)
|
\|/
v
SECOND.BAT ----> @echo off
echo Running Seond.bat
(misc commands)
|
\|/
v
:: Back from SECOND.BAT <--+
|
\|/
v
ECHO Back from second.bat
|
\|/
v
END