English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm a programmer (Perl, some very basic Java) and have turned to writing a batch script for work.

What I want to do is ping a server and IF it's a success, GOTO line, if not GO TO line.

How do you check results in batch? Is there a way? Any sort of variables, regexes, etc?

2007-10-11 10:11:14 · 4 answers · asked by biggestperlnerd 3 in Computers & Internet Programming & Design

4 answers

With very little code, you can take the output of "ping" and pipe it through "find" and take your action.
=============
@echo off

ping -n 1 %1 | find /i "reply from" && goto :alive

:dead
echo dead
goto :eof

:alive
echo alive

2007-10-15 00:14:37 · answer #1 · answered by Kevin 7 · 3 0

It's been a while since I wrote a batch script, but here's the rough (and I do mean rough! lol) sort of thing you're looking for. There may well be a cleaner way of doing this.

@echo off

ping -n 1 www.yahoo.com > nul

if ERRORLEVEL 1 goto BAD

:GOOD
echo "Ping was successful!"
goto DONE

:BAD
echo "Ping failed."

:DONE

pause

2007-10-12 00:09:22 · answer #2 · answered by Bob R 4 · 0 0

regrettably, you do no longer come here 24hrs earlier the due date to do your homework: that's only too overdue! Now, bear in mind one mandatory difficulty: - js code is on the consumer's device. - Hypertext Preprocessor is on the server. they're MILES appart. - Hypertext Preprocessor runs first, and frequently generate the js code, then deliver it to the consumer. In different words, Hypertext Preprocessor variables are time-venerated to Hypertext Preprocessor, and can be sent to js, yet no longer any incorrect way around!!! As you're utilising ajax, it rather is the only thank you to do it: deliver an HTTPrequest to a Hypertext Preprocessor function. That request will incorporate the consequence of your js script. Your Hypertext Preprocessor function can then use the archives won to do despite you go with, inclusive of sending an replace on your consumer visual exhibit unit. no longer understanding how your AJAX is desperate-up, i won't be able to truly help you, yet you get the basics. js establishes the variable. ajax takes that variable and deliver it to Hypertext Preprocessor. (The "how" relies upon on your setup) Hypertext Preprocessor gets the variable and writes it to a report.

2016-12-14 14:49:20 · answer #3 · answered by ? 4 · 0 0

The status variable can be used to determine the exit status of the previous command:

#!/bin/csh -f

ping -c 1

if ( $status == 0 ) then
echo OK
else
echo NOT OK
endif

2007-10-11 10:22:23 · answer #4 · answered by Anonymous · 0 0

fedest.com, questions and answers