Page 1 of 1

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

Posted: 16 May 2012 21:24
by taripo
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

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

Posted: 16 May 2012 21:31
by Fawers
Remove /b from exit.

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

Posted: 16 May 2012 21:41
by taripo
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.

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

Posted: 16 May 2012 21:47
by Fawers
Then try leaving exit without the /b switch and running your batch from a child itself.

Code: Select all

cmd /c a.bat

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

Posted: 16 May 2012 21:59
by taripo
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>

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

Posted: 16 May 2012 22:09
by Fawers
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.

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

Posted: 16 May 2012 22:15
by taripo
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"

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

Posted: 16 May 2012 22:22
by Fawers
"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.

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

Posted: 17 May 2012 00:19
by dbenham
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