Page 1 of 1

Why does | to a non-existent command, cause an Exit?

Posted: 16 May 2012 20:24
by taripo

Code: Select all

C:\>(echo d | azacav) & echo f
'azacav' is not recognized as an internal or external command,
operable program or batch file.


azacav is a program that doesn't exist.. so can be any random string.

It exits, it doesn't get as far as executing echo f and displaying 'f'

Re: Why does | to a non-existent command Exit?

Posted: 16 May 2012 20:34
by Fawers
Try adding a pause to this code.

Edit:
Strange. I actually tried it. Pause has no effect.

But anyway, why would you want to pipe a command to a "random string"?

Re: Why does | to a non-existent command Exit?

Posted: 16 May 2012 20:42
by taripo
Why I want to try to run that line, is to ask anybody that might know, the question of what is going on, why it behaves like that.

It's obviously something about the way batch files work or interpret things. Or the shell. And i'm asking anybody that might know, the question of what's going on there.

Re: Why does | to a non-existent command, cause an Exit?

Posted: 17 May 2012 01:13
by foxidrive
It seems to me that cmd interpreter is parsing the line and halting on an error.

Re: Why does | to a non-existent command, cause an Exit?

Posted: 17 May 2012 01:24
by taripo
yes I think in light of Dave Benham's answer,
viewtopic.php?f=3&t=3329

that is what is happening here.

It's a useful behaviour.

Re: Why does | to a non-existent command, cause an Exit?

Posted: 17 May 2012 06:53
by Squashman

Code: Select all

H:\>(echo d | CALL azacav) & echo f
'azacav' is not recognized as an internal or external command,
operable program or batch file.
f

Re: Why does | to a non-existent command, cause an Exit?

Posted: 19 May 2012 15:13
by Ed Dyreen
'
Not always, remember the cmd options /c and /k

Code: Select all

cmd /?|more
'test.CMD'

Code: Select all

@echo off &start "CMD" %comspec% /k "%~dp0\test1.CMD" /ThisWorks &exit
'test1.CMD'

Code: Select all

@echo off &setlocal enableDelayedexpansion

(echo. |call azacav) &echo.yesyes

pause
exit
@dBenham used a fatal syntax error but yours is a logic error, whether it is fatal, depends on how your batch was started.
viewtopic.php?p=16359#p16359