Page 1 of 1

IF ELSE statement based on ping result

Posted: 06 Dec 2010 15:56
by smallducktown
Hey guys,

I'm making a script wich opens a file (at random), but this file is placed on a remote disk. So i want to ping the IP adress to make shure there's connectivity. If there is connectivity it should open a file on the remote disk, else it should open a local file. I got the open file part all worked out, its only the if/else part i need.

ping 129.168.1.2
if "succes"
*open remote file *
else
*open local file *

Is it possible and if so, could you help me with that?
Thnx

Re: IF ELSE statement based on ping result

Posted: 06 Dec 2010 16:46
by aGerman
You could use the ERRORLEVEL, or maybe more simple: && (command was successful) and || (command failed)

Code: Select all

@echo off
ping -n 1 129.168.1.2 >nul &&(
  *open remote file *
)||(
  *open local file *
)

Regards
aGerman

Re: IF ELSE statement based on ping result

Posted: 07 Dec 2010 12:33
by smallducktown
thnx :D