have my script splitted into two batch files as i dont know how to combine it:
short so you get an idea:
1.bat : calls 2.bat with args, sorts its output and makes lines unique
FOR /F ... (2.bat %1 ^| sort) DO (...)
the do part compares lines to each other and excludes identical lines using a linebuffer
2.bat : prints strings as a result of an FOR loop
FOR ... DO ECHO
in bash this might look like this: (piping is easy)
(command) | while read line ; do echo $line ; done | sort | uniq
i really dont know how to process the final output of a FOR loop in windows batch to use its result with another loop (without using temp files for result buffering)
This is the whole code with jeb's solution applied:
@echo off
setlocal EnableDelayedExpansion
REM *** This "goto" to a label, if there is one embedded in %~0 -
FOR /F "delims=: tokens=3" %%L in ("%~0") do goto :%%L
REM *** The second part calls this batch file, but embedd a label to be called
FOR /F "usebackq" %%A IN (`echo dummy ^| call %~d0\:main:\..\%~pnx0 %1 ^| SORT`) DO (
IF NOT "%%A"=="!buff!" SET str=!str!%%A
SET buff=%%A
)
ECHO %str:.dll=;%
endlocal
GOTO :eof
REM *** This function will be called in the pipe, but runs in batch context
:main
CD %1
:sub
FOR %%A IN (*.dll *.exe) DO dumpbin /DEPENDENTS %%A | FINDSTR /I "DLL" | FINDSTR /V "Dump :"
FOR /D %%B IN (*) DO (
CD %%B
CALL :sub
CD..
)
GOTO :eof
it returns a single line with runtime dependencies of all files inside a folder [arg1] and all its subfolders : the .dll part of the output string is stripped to suit my needs
ADVAPI32;COMCTL32;COMDLG32;GDI32;KERNEL32;ole32;SHELL32;USER32;WININET;
here is the counterpart on osx using pev tools:
#!/bin/sh
find "${1}" -type f \( -iname "*.dll" -o -iname "*.exe" \) | while read pe ; do
readpe -i "${pe}" | grep -i '.dll' | awk '{print $2}'
done | sort | uniq | sed 's/.[dD][lL][lL]//g;' | tr '\n' ';' ## have the BSD sed release and can't use I with sed