View unanswered posts | View active topics It is currently 17 Apr 2014 00:41



Post new topic Reply to topic  [ 9 posts ] 
How do you Exit from all child and parent batch processes? 
Author Message

Joined: 01 Aug 2011 13:48
Posts: 140
Post How do you Exit from all child and parent batch processes?
How do you Exit from all child and parent batch processes?


Code:
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


16 May 2012 21:24
Profile

Joined: 08 Apr 2012 17:11
Posts: 187
Post Re: How do you Exit from all child and parent batch processe
Remove /b from exit.


16 May 2012 21:31
Profile WWW

Joined: 01 Aug 2011 13:48
Posts: 140
Post Re: How do you Exit from all child and parent batch processe
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.


16 May 2012 21:41
Profile

Joined: 08 Apr 2012 17:11
Posts: 187
Post Re: How do you Exit from all child and parent batch processe
Then try leaving exit without the /b switch and running your batch from a child itself.
Code:
cmd /c a.bat


16 May 2012 21:47
Profile WWW

Joined: 01 Aug 2011 13:48
Posts: 140
Post Re:How do you Exit from all child and parent batch processes
Fawers wrote:
Then try leaving exit without the /b switch and running your batch from a child itself.
Code:
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>


16 May 2012 21:59
Profile

Joined: 08 Apr 2012 17:11
Posts: 187
Post Re: Re:How do you Exit from all child and parent batch proce
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.


16 May 2012 22:09
Profile WWW

Joined: 01 Aug 2011 13:48
Posts: 140
Post Re: Re:How do you Exit from all child and parent batch proce
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"


16 May 2012 22:15
Profile

Joined: 08 Apr 2012 17:11
Posts: 187
Post Re: How do you Exit from all child and parent batch processe
"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.


16 May 2012 22:22
Profile WWW
Expert

Joined: 12 Feb 2011 21:02
Posts: 1118
Location: United States (east coast)
Post Re: How do you Exit from all child and parent batch processe
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:
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:
@echo off
if "%~1" neq "_GO_" (
  cmd /c "%~f0" _GO_ %*
  exit /b
)
REM Your normal code goes here
exit


Dave Benham


17 May 2012 00:19
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], npocmaka_, Yahoo [Bot] and 17 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Forum style by Vjacheslav Trushkin for Free Forums/DivisionCore.