[英]findstr command not working in windows batch file
我在Windows中制作了一個簡單的批處理文件。 它可以進行報告以查找包含錯誤的URL。 但所有URL僅回顯成功。
wget命令標准輸出似乎為空。 重定向管道不起作用。 怎么了??
@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
)
我的問題解決了。 一個好的答案的修改后的代碼
@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
)
您嘗試讀取的wget診斷信息將寫入stderr,而不是stdout。 因此,您只需要在管道之前將stderr重定向到stdout即可。
假設所有wget參數都是正確的,我將編寫如下代碼:
@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!
我想,您只想echo
result.txt
而不是終端/控制台。
if %errorlevel% == 0 (
echo error >> result.txt > /dev/null 2>&1
) else (
echo success >> result.txt > /dev/null 2>&1
)
這些更改不允許顯示在控制台/終端上
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.