0

Suppose I have some commands in a bat file :

echo 1
copy existingFile1 c:
echo 2
copy existingFile1 notExistingDrive:
echo 3
attrib -r attrib notExistingFile

Those are just demos of commands that contains successful commands and also "not-ran-to-completion" return codes.

Visualization :

enter image description here

Question

Is there any way I can get an indication that at least one operation has not-ran-to-completion ?

psuedo :

do something1
do something2
do something3
if noErrorsAll(something1,something2,something3)
 do something4

NB I prefer not to check everytime "if exists".There can be other halts than "not-exists"

Royi Namir
  • 5,598
  • 14
  • 47
  • 70
  • possible duplicate of [How to check the exit code of the last command in batch file?](http://superuser.com/questions/194662/how-to-check-the-exit-code-of-the-last-command-in-batch-file) – Ƭᴇcʜιᴇ007 Dec 23 '14 at 20:42
  • @Ƭᴇcʜιᴇ007 No. it's not a dup. [see this image](http://i.imgur.com/m3iCEzW.png) as you can see - it didnt find the file and yet - errorlevel is 0. – Royi Namir Dec 24 '14 at 08:44

1 Answers1

0

Redirect/Append the STDERR from each command to (e.g.) log.txt, then read the contents or size into a variable and test for empty/zero bytes.