Ok I have found a few questions on this, but each are saying make sure the use CALL
and exit \b
or goto eof
in the 2nd bat file but for some reason I am not getting this to work, I have tried both, the batch file exits every time after executing the first call statement:
batch file 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
Execution:
C:\Users\ots>myscript.bat
C:\Users\ots>del files
C:\Users\ots>dir /B /O-D | find "test2" 1>tmp
C:\Users\ots>dir /B /O-D | find "test3" 1>tmp2
C:\Users\ots>CALL head 1 tmp 1>files
C:\Users\ots>
How can I get it to run the second "tmp2" Call line?
Thanks!