• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

error levels in bat and cmd

 
Ranch Hand
Posts: 75
Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One of the differences that I read from ( http://www.differencebetween.net/technology/difference-between-cmd-and-bat/ , http://ss64.com/nt/errorlevel.html ) about a .cmd file and .bat file is the way they handle error variables. Articles are saying When using BAT, this variable (error level variable) is only changed once an actual error occurs and no change in state occurs when the each command executes successfully. This is not true for CMD as the errorlevel variable would still change state even if no errors occur. .
But I found no difference when I executed the .bat and .cmd file.


The above code when executed with a .bat and .cmd extension is giving the same result. i.e shown in pic. I think .cmd file should show 0 instead of 9009 in the second output
error.JPG
[Thumbnail for error.JPG]
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know why that isn't working as expected, I can only think it's because of the error type involved.

If you run your test again and use something like copy to copy a non existent file in a .bat file (which will set errorlevel to 1) and then copy an existing file in a .cmd file you will see the errorlevel is reset to 0.
 
reply
    Bookmark Topic Watch Topic
  • New Topic