DosTips.com

A Forum all about DOS Batch
It is currently 06 May 2016 01:20

All times are UTC-06:00




Post new topic  Reply to topic  [ 9 posts ] 
Author Message
PostPosted: 16 May 2012 21:24 
Offline

Joined: 01 Aug 2011 13:48
Posts: 200
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


Top
   
PostPosted: 16 May 2012 21:31 
Offline

Joined: 08 Apr 2012 17:11
Posts: 187
Remove /b from exit.


Top
   
PostPosted: 16 May 2012 21:41 
Offline

Joined: 01 Aug 2011 13:48
Posts: 200
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.


Top
   
PostPosted: 16 May 2012 21:47 
Offline

Joined: 08 Apr 2012 17:11
Posts: 187
Then try leaving exit without the /b switch and running your batch from a child itself.
Code:
cmd /c a.bat


Top
   
PostPosted: 16 May 2012 21:59 
Offline

Joined: 01 Aug 2011 13:48
Posts: 200
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>


Top
   
PostPosted: 16 May 2012 22:09 
Offline

Joined: 08 Apr 2012 17:11
Posts: 187
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.


Top
   
PostPosted: 16 May 2012 22:15 
Offline

Joined: 01 Aug 2011 13:48
Posts: 200
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"


Top
   
PostPosted: 16 May 2012 22:22 
Offline

Joined: 08 Apr 2012 17:11
Posts: 187
"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.


Top
   
PostPosted: 17 May 2012 00:19 
Offline
Expert

Joined: 12 Feb 2011 21:02
Posts: 1635
Location: United States (east coast)
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


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 9 posts ] 

All times are UTC-06:00


Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 10 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® Forum Software © phpBB Limited