Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Invalid (missing) command crashes batch file in pipeline

11 views
Skip to first unread message

Kenny McCormack

unread,
Nov 17, 2020, 9:03:05 PM11/17/20
to
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?

--
Modern Christian: Someone who can take time out from using Leviticus
to defend homophobia and Exodus to plaster the Ten Commandments on
every school and courthouse to claim that the Old Testament is merely
"ancient laws" that "only applies to Jews".

JJ

unread,
Nov 18, 2020, 7:42:54 AM11/18/20
to
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.
0 new messages