How do you Exit from all child and parent batch processes?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
taripo
Posts: 209
Joined: 01 Aug 2011 13:48

How do you Exit from all child and parent batch processes?

#1 Post by taripo » 16 May 2012 21:24

How do you Exit from all child and parent batch processes?


Code: Select all

C:\>type a.bat
echo abc
call b.bat
echo def
C:\>type b.bat
echo hello
exit /b
C:\>a

C:\>echo abc
abc

C:\>call b.bat

C:\>echo hello
hello

C:\>exit /b

C:\>echo def
def

C:\>


I want the output to not include echo def. I want the EXIT, to leave both b.bat AND a.bat

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: How do you Exit from all child and parent batch processe

#2 Post by Fawers » 16 May 2012 21:31

Remove /b from exit.

taripo
Posts: 209
Joined: 01 Aug 2011 13:48

Re: How do you Exit from all child and parent batch processe

#3 Post by taripo » 16 May 2012 21:41

Fawers wrote:Remove /b from exit.


No, that still won't do it. Doing exit as you suggest, exits the cmd prompt too. I want to stay in the cmd prompt.

And I want to exit from all child and parent batch processes.

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: How do you Exit from all child and parent batch processe

#4 Post by Fawers » 16 May 2012 21:47

Then try leaving exit without the /b switch and running your batch from a child itself.

Code: Select all

cmd /c a.bat

taripo
Posts: 209
Joined: 01 Aug 2011 13:48

Re:How do you Exit from all child and parent batch processes

#5 Post by taripo » 16 May 2012 21:59

Fawers wrote:Then try leaving exit without the /b switch and running your batch from a child itself.

Code: Select all

cmd /c a.bat


Well, regarding what you're doing, spawning a new shell to run the batch file

No I don't want to execute a.bat any differently than I execute my other bat files. Just a.bat
C:\whatever>a <ENTER>

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: Re:How do you Exit from all child and parent batch proce

#6 Post by Fawers » 16 May 2012 22:09

taripo wrote:No I don't want to execute a.bat any differently than I execute my other bat files. Just a.bat
C:\whatever>a <ENTER>

Then the only thing you can do is remove "echo def". As far as I understand, you don't need it at all if you want to ommit it.

taripo
Posts: 209
Joined: 01 Aug 2011 13:48

Re: Re:How do you Exit from all child and parent batch proce

#7 Post by taripo » 16 May 2012 22:15

Fawers wrote:
taripo wrote:No I don't want to execute a.bat any differently than I execute my other bat files. Just a.bat
C:\whatever>a <ENTER>

Then the only thing you can do is remove "echo def". As far as I understand, you don't need it at all if you want to ommit it.


DUDE..
That code is -to demonstrate- the question i'm asking (and if you don't know, then you don't know, but maybe somebody else does)


The question is

"How do you Exit from all child and parent batch processes"

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: How do you Exit from all child and parent batch processe

#8 Post by Fawers » 16 May 2012 22:22

"Dude",

I gave you 2 answers. The first time I told you to remove /b from exit. You said you didn't want cmd to close as well. I said to run the code with cmd /c. Still it seems that you don't want to accept it. "I don't want to execute a.bat any differently than I execute my other bat files."

Those are two ways; the second one prevents cmd from closing. If none of them is good for you, just remove everything after your call command. If there's nothing else to run, the batch will finish and you won't get any extra, undesired output.

Besides, why don't you post the actual code? It would be better to work on a real code rather than a "demonstration" one.

dbenham
Expert
Posts: 1961
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: How do you Exit from all child and parent batch processe

#9 Post by dbenham » 17 May 2012 00:19

The only way I know to exit all child and parent batch processes without closing the CMD shell is to intentionally introduce a fatal syntax error. (jeb introduced this technique to me)

Code: Select all

call :kill 2>nul

:kill - Kills all batch processing with a fatal syntax error
()


If you want to kill the current batch file but not any parent batch file, then you can use a variation of what Fawers was suggesting.
Your batch file can re-execute itself via CMD and use EXIT to kill it.

Code: Select all

@echo off
if "%~1" neq "_GO_" (
  cmd /c "%~f0" _GO_ %*
  exit /b
)
REM Your normal code goes here
exit


Dave Benham

Post Reply