'Is it possible for a batch script to 'catch' a powershell error?
This is my batch code and it's works find as long as the url being checked is a valid url, but gets the following error if you put in an invalid url URL Status= ( was unexpected at this time.
@Echo Off
Set CheckUrl=`Powershell.exe -nologo -NoProfile -command "(Invoke-WebRequest -Uri http://exceedtstab.infarmbureau.com/Exceed).StatusCode"`
For /f "usebackqdelims=" %%A in (
%CheckUrl%
) Do Set UrlStatus=%%A
Echo URL Status=%UrlStatus%
IF %UrlStatus% == 200 (
Echo URL Connected to internet
goto :eof
) else (
Echo URL Not connected to internet
)
Solution 1:[1]
Or you can test the "UrlStatus" variable with double quotes around it, just in case it's blank; then you won't get that error message, "( was unexpected at this time."
IF "%UrlStatus%" == "200" (
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | js2010 |
