Kumar
Kumar

Reputation: 1

stop when one batch fails from one machine

I have two batch files located on two different machines which done one task.

Lets say first batch is on machine A, second batch is on machine B.

I want that if one batch fails on machine A fails, then second batch on machine B should skip.

Because there is no point running second batch file if first one fails in my script.

Any thoughts.

Thanks.

Upvotes: 0

Views: 43

Answers (3)

MC ND
MC ND

Reputation: 70933

You can use WAITFOR

In machine B, to wait for 2min to script A to finalize

WAITFOR /T 120 mySignal
IF errorlevel 1 (
    Echo Script A failed
)

And in machine A, if everything ok, send signal to machine B to continue

WAITFOR /S machineB /SI mySignal

Upvotes: 2

foxidrive
foxidrive

Reputation: 41234

It depends on how the Machine A batch file fails.

If the exe in batch A exits then you can use PSexec to check the tasklist on Machine A and branch in batch B if it is not running.

However if the EXE just doesn't respond then it will still be in the tasklist and you will have to detect if it is not responding.

Upvotes: 1

Ilya
Ilya

Reputation: 4689

Try to use IF ERRORLEVEL construction.

Your first batch file should return special codes if everithing is ok (for example, EXIT 0) and if there is a problem (for example, EXIT 1).

And your script will check this error code before run of second batch file. It will look like this: IF ERRORLEVEL 0 CALL SECOND.BAT

Upvotes: 0

Related Questions