Reputation: 23
I made a simple batch file in windows. it works reporting to find the URL including error. but all URL echo only success.
wget command stdout seems like empty. redirection pipe is not work. what's wrong??
@echo off
for /f "delims=" %%i in (TEST.txt) do call :request %%i
set /p in=Finish!
:request
echo | set /p= %1 >> result.txt
wget.exe -T 3 --tries=2 %1 | findstr /I "error"
if %errorlevel% == 0 (
echo error >> result.txt
) else (
echo success >> result.txt
)
My problem is solved. Modified code from a good answer
@echo off
set logFile="log.txt"
set resultFile="result.txt"
for /f "delims=" %%i in (TEST.txt) do call :request %%i
set /p in=Finish!
:request
echo|set /p= %1 >> %resultFile%
wget.exe -P download -T 3 --tries=2 %1 2>&1 | tee -a %logFile% | findstr /I "error" > nul
if %errorlevel% == 0 (
echo error >> result.txt
) else (
echo success >> result.txt
)
Upvotes: 0
Views: 1669
Reputation: 130809
The wget diagnostic information that you are trying to read is written to stderr, not stdout. So you simply need to redirect stderr to stdout before your pipe.
Assuming all your wget arguments are correct, I would write the code as follows:
@echo off
>result.txt (for /f "delims=" %%i in (TEST.txt) do (
wget.exe -T 3 --tries=2 %%I 2>&1|findstr /i error >nul&&echo %%i ERROR||echo %%i SUCCESS
))
echo Finished!
Upvotes: 1
Reputation: 1305
I assume, you want to echo
only to result.txt
instead to terminal/console.
if %errorlevel% == 0 (
echo error >> result.txt > /dev/null 2>&1
) else (
echo success >> result.txt > /dev/null 2>&1
)
These changes not allowed to display on console/terminal
Upvotes: 0