Yes, you can do this in a Windows batch file using string manipulation and conditional execution (IF statements). Here's how you can read lines from input (either from a file or standard input), check if they contain the substring anywhere.com, and call either subroutine A or subroutine B accordingly.
✅ Example Batch File
@echo off
setlocal enabledelayedexpansion
REM === Read from a file line by line ===
for /f "usebackq delims=" %%L in ("input.txt") do (
set "line=%%L"
REM Check if the line contains "anywhere.com"
echo !line! | findstr /i "anywhere.com" >nul
if !errorlevel! equ 0 (
call :SubroutineA "!line!"
) else (
call :SubroutineB "!line!"
)
)
goto :EOF
:SubroutineA
echo Subroutine A: %~1
goto :EOF
:SubroutineB
echo Subroutine B: %~1
goto :EOF
🔍 Explanation:
for /f "usebackq delims=" %%L in ("input.txt"): Reads each line from input.txt.
set "line=%%L": Stores the line in a variable.
echo !line! | findstr /i "anywhere.com": Searches case-insensitively for anywhere.com.
>nul: Suppresses output of findstr.
if !errorlevel! equ 0: Checks if the string was found.
- Calls either
:SubroutineA or :SubroutineB with the line passed as an argument.
🔄 If Reading from Standard Input:
If you're piping input into the batch file (e.g., type input.txt | myscript.bat), replace the for loop with:
for /f "delims=" %%L in ('more') do (
...
)
⚠️ But note: handling standard input robustly in batch is tricky. A better approach may be to structure your script to accept a filename argument:
@echo off
if "%~1"=="" (
echo Usage: %~nx0 inputfile
exit /b
)
setlocal enabledelayedexpansion
for /f "usebackq delims=" %%L in ("%~1") do (
...
)
Then run it like:
myscript.bat input.txt
Let me know if you'd like to modify this to read from the console interactively instead.