writing batch files. help

Discussion in 'Software' started by taz55, Jun 10, 2006.

  1. taz55

    taz55 Private First Class

    ok so i got this

    @echo off
    this will ping homer then launch vnc viewer
    call homer.bat

    cd\

    cd program files

    cd realvnc

    cd vnc4

    vncviewer.exe 192.168.1.2

    the batch runs beutiful it pings the connection then launches and automaticly connects to the host.
    what i want to know is if there is a way to make it only launch vnc if ping is succesful
     
  2. taz55

    taz55 Private First Class

    no one huh.
     
  3. Toni_1947

    Toni_1947 Command Sergeant Major

  4. jconstan

    jconstan MajorGeek

    @echo off

    ping -n 1 192.168.1.2 > NULL

    if errorlevel 1 echo 192.168.1.2 not responding


    The ping command returns errorlevel 0 if sucessful and errorlevel 1 if not.
     
  5. taz55

    taz55 Private First Class

    could you explain that to me a little bit i am lost. like where it goes into my script.
     
  6. jconstan

    jconstan MajorGeek

    The most likely place is somewhre in homer.bat, but you didn't post that code. I assume that's where the pinging takes place?
     
  7. taz55

    taz55 Private First Class

    yes in homer.bat the command is

    ping homer

    and then thats it.
     
  8. jconstan

    jconstan MajorGeek

    Replace the code in homer.bat with this

    @echo off
    ping -n 1 192.168.1.2 | find "TTL=" || EXIT

    If 192.168.1.2 does not answer the ping the batch file will exit.
     
  9. taz55

    taz55 Private First Class

    thank you. could you explain to me why it does that so i can do it later and understand it.
     
  10. jconstan

    jconstan MajorGeek

    I don't understand what you mean by "why it does that" ?

    The output of the ping command is sent (piped) to the find command which looks for "TTL=" in the information returned from the ping command. It will only find the "TTL=" in the ping return if 192.168.1.2 answers. If there is no "TTL=" in the data returned from the ping command then an ERRORLEVEL 0 condition will be returned which will execute the command after the "||" and EXIT the program instead of doing a RETURN from the call.
     
    Last edited: Jun 12, 2006
  11. taz55

    taz55 Private First Class

    that is what i wanted to know. thanks alot.
     
  12. jconstan

    jconstan MajorGeek

    No problem.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds