Reputation: 4066
How do I convert the below code into CMD line code for windows?
r=`wget -q www.someurl.com`
if [ $r -ne 0 ]
then echo "Not there"
else echo "OK"
fi
Upvotes: 0
Views: 2187
Reputation: 9266
Using cmd's short-circuit &&
and ||
operators:
wget.exe -q www.someurl.com && (
echo OK
) || (
echo Not there
)
If the statements are short, you can make this into a one-liner
wget.exe -q www.someurl.com && ( echo OK ) || ( echo Not there )
This method only notes if the exit code is zero or nonzero. If you need the actual exit code, use the if
statements in Stuart Siegler's answer.
Upvotes: 0
Reputation: 1736
something like this:
wget.exe -q www.someurl.com
if errorlevel 1 (
echo not there
) ELSE (
echo ok
)
the error can be printed with
echo Failure is %errorlevel%
Upvotes: 1