On Wed, 18 Nov 2020 02:03:04 -0000 (UTC), Kenny McCormack wrote:
> Something I just discovered, quite by accident.
>
> Normally, in a batch file, if I try to run a non-existent command, it just
> generates an error message and continues:
>
>:: My batch file
> floofklsdf
> echo Well, that didn't work, but we're still running...
>
> But if I do a pipeline, like this:
>
>:: My batch file
> someValidCommand | floofklsdf
> echo Well, that didn't work, and now we're crashed.
>
> The echo does not get executed. The batch blows up (exits) after the
> pipeline fails.
>
> Is this a good thing?
IMO, in terms of programming, yes. Any unhandled runtime error should
trigger a fatal error and terminate the whole program in order to prevent
potential damage or incorrect result due to missing, incomplete, or
incorrect data.
However, this particular problem should normally be handleable using
ErrorLevel, but CMD.EXE treats it as a fatal error instead.
I don't know whether it is intended or it's a bug, but this error treatment
is no longer compatible with MS-DOS
COMMAND.COM, and it applies to CMD.EXE
since NT3.x.