好的,我在这方面发现了一些问题,但每个问题都是说确保在第二个bat文件中使用CALL和exit \b或goto eof,但由于某些原因,我尝试了这两种方法,每次执行第一个调用语句之后,批处理文件都会退出:
批处理文件1 (myscript.bat):
:@echo off
del files
dir /B /O-D | find "test2" > tmp
dir /B /O-D | find "test3" > tmp2
CALL head 1 tmp > files
CALL head 1 tmp2 >> fileshead.bat:
@echo off
if [%1] == [] goto usage
if [%2] == [] goto usage
call :print_head %1 %2
goto :eof
REM
REM print_head
REM Prints the first non-blank %1 lines in the file %2.
REM
:print_head
setlocal EnableDelayedExpansion
set /a counter=0
for /f ^"usebackq^ eol^=^
^ delims^=^" %%a in (%2) do (
if "!counter!"=="%1" goto :eof
echo %%a
set /a counter+=1
)
goto :eof
:usage
echo Usage: head.bat COUNT FILENAME处决:
C:\Users\ots>myscript.bat C:\Users\ots>del文件 C:\Users\ots>dir /B /O-D =查找"test2“1>tmp C:\Users\ots>dir /B /O-D =查找"test3“1>tmp2 C:\Users\ots>CALL头1 tmp 1>files C:\Users\ots>
如何让它运行第二条"tmp2“呼叫线?
谢谢!
发布于 2012-10-26 22:21:04
您的代码很好,这两个调用都确实进行了。
问题是您在head.bat中将echo设置为OFF,所以在第一次调用之后,您的命令不会在控制台上得到回显,但这并不意味着没有调用该文件。
要验证这一点,请从@echo off中删除head.bat,然后将看到第二个CALL命令。
https://stackoverflow.com/questions/13094973
复制相似问题