好的我已经找到了一些问题,但每个人都说要确保在第二个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 >> files
head.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:\用户\ OTS> myscript.bat
C:\ Users \ ots> del files
C:\ Users \ ots> dir / B / O-D |找到“test2”1> tmp
C:\ Users \ ots> dir / B / O-D |找到“test3”1> tmp2
C:\ Users \ ots> CALL head 1 tmp 1> files
C:\用户\ OTS>
如何让它运行第二个“tmp2”呼叫线?
谢谢!
答案 0 :(得分:3)
你的代码很好,两个电话确实都是。
问题是你在head.bat中将echo设置为OFF,所以在第一次调用之后,你的命令不会在控制台上回显,但这并不意味着文件没有被调用。
要验证这一点,请从head.bat中删除@echo off
,然后您将看到第二个CALL命令。