0

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
Himanshu
  • 4,327
  • 16
  • 31
  • 39
Hard worker
  • 3,916
  • 5
  • 44
  • 73
  • you ask this question in [link](http://stackoverflow.com/questions/29290564/how-to-do-an-if-statement-based-on-wget-retrieved-content) ! see my answer in this link `$?` that exist in bash for check in cmd you should check `if errorlevel` – Soheil Mar 27 '15 at 01:00
  • possible duplicate of [How do I get the application exit code from a Windows command line?](http://stackoverflow.com/questions/334879/how-do-i-get-the-application-exit-code-from-a-windows-command-line) – sashoalm Mar 28 '15 at 21:01

2 Answers2

1

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%
Stuart Siegler
  • 1,686
  • 4
  • 30
  • 38
0

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.

Ryan Bemrose
  • 9,018
  • 1
  • 41
  • 54