我有.bat文件。它看起来像下一个
....many commands1
ftp -i -s:copy.txt
...many commands2
copy.txt包含下一个命令
open ...
login
password
get file
bye
当我执行我的.bat文件时,它将继续工作
many commands1
ftp commands
但许多命令2仍然没有被执行。
答案 0 :(得分:4)
声音就像您的command2
命令之一可能在不使用CALL
命令的情况下调用(启动)批处理文件一样。 (在底部是两个流程图,解释了使用和不使用CALL
的后果。)请参阅**使用和不使用CALL
的后果。
如果我的初步预感不正确,您需要开始采取措施调试批处理文件。
注释掉所有@ECHO OFF
语句,并在批处理文件中添加一些PAUSE
甚至ECHO
语句。这有助于您找到错误。另外,请记住,如果您希望代码执行批处理文件,则需要使用CALL
命令,然后在完成执行{{1}后继续执行CALL
批处理文件批处理文件。此外,请注意,如果您CALL
任何包含CALL
语句的批处理文件,即使控制权返回ECHO OFF
文件后,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
行更改为RUN.BAT
,则执行流程将如下所示:
CALL SECOND.BAT