I wrote a batch process via bingchat, About Adding Proxy Automation for WSA,and one of the functions performs well when carried out on its own, but an error occurs when adding it to an if statement, and the error associated with it is FINDSTR: Cannot open。I'm totally new to this.
this is code
@echo off
:menu
cls
echo 1. Set Android proxy to local IP address
echo 2. Cancel Android proxy
set /p choice=Enter your choice (1 or 2):
if "%choice%"=="1" (
echo Your local IP addresses are:
ipconfig | findstr /c:"IPv4 Address"
set /p ip=Please enter the number of the IP address you want to use as the proxy:
for /f "tokens=2 delims=: " %%f in ('ipconfig ^| findstr /c:"IPv4 Address"') do (
set /a count+=1
if !count! == %ip% set ip=%%f
)
setlocal enableextensions
set "configFile=%userprofile%\.config\clash\config.yaml"
for /f "tokens=2 delims=: " %%a in (' findstr /c:"mixed-port" "%configFile%"') do set "port=%%a"
echo The port number of Clash is %port%.
adb shell settings put global http_proxy %ip%:%port%
adb shell settings put global https_proxy %ip%:%port%
echo Proxy has been set to %ip%:%port%.
pause
endlocal
) else if "%choice%"=="2" (
adb shell settings put global http_proxy :0
adb shell settings put global https_proxy :0
echo Proxy has been cancelled.
) else (
echo Invalid choice. Please enter 1 or 2.
pause
goto menu
)
pause
The port port code segment in search yaml can work normally when it is taken out alone, but it will display the error of FINDSTR: Cannot open when it is put into the if statement. I try to add something like the if statement to the code segment that can run normally. Brackets, an error occurred in the result, I don't know how the brackets work, and I didn't find the corresponding article on the Internet