Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#1
Post
by Ed Dyreen » 10 Nov 2012 09:28
'parent.CMD'
Code: Select all
@echo off &prompt $G
call child.CMD
echo.after call
start /b /wait "" child.CMD
echo.after start %=( never gets here )=%
pause
exit
'child.CMD'
Code: Select all
echo.cmdcmdline=%cmdcmdline%_
exit /b
Code: Select all
cmdcmdline=cmd /c ""...\child.cmd" "_
after call
cmdcmdline=C:\WINDOWS\system32\cmd.exe /K child.CMD_
>
Using START requires EXIT without /b otherwise it crash.
But using EXIT without /b terminates any parent that CALLs it.
If I could determine how the batch was started, the exit could be set to work, always

Code: Select all
if !called!==1 (exit /b !err!) else exit !err!
Maybe I use parameter 2 of cmdCmdLine, but does it work, always, is it safe ?
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#2
Post
by Ed Dyreen » 10 Nov 2012 09:48
I knew there were Gremlins inside.If a batch starts a batch that itself calls upon another batch, cmdCmdLine gives the parents paramRAW

-
dbenham
- Expert
- Posts: 2461
- Joined: 12 Feb 2011 21:02
- Location: United States (east coast)
#3
Post
by dbenham » 10 Nov 2012 15:41
Why must you use
START /B /WAIT CHILD.CMD
Why not use
CMD /C CHILD.CMD instead? Then your child can use
EXIT /BDave Benham
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#4
Post
by Ed Dyreen » 10 Nov 2012 16:18
dbenham wrote:Why not use CMD /C CHILD.CMD instead? Then your child can use EXIT /B
Hmm, I forgot to add option /LOW
Code: Select all
start "" /low /b /wait "child.CMD"
CMD /C is possible, but it delay my batches even further, I would have to call an external program to adjust priorities
Hope it make more sense now.
-
dbenham
- Expert
- Posts: 2461
- Joined: 12 Feb 2011 21:02
- Location: United States (east coast)
#5
Post
by dbenham » 10 Nov 2012 16:26
start "" /low /b /wait "cmd /c child.CMD" should work with
exit /b in your child

-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#6
Post
by Ed Dyreen » 10 Nov 2012 16:59
dbenham wrote:start "" /low /b /wait "cmd /c child.CMD" should work with
exit /b in your child

Uhh, I'm with stupid

Really cool, I think I can now use start /options AND exit selectively.
Code: Select all
@echo off &setlocal enableDelayedExpansion
start "" /low /b /wait "cmd /c" child.cmd
echo.after start cmd /c
start "" /low /b /wait "cmd /k" child.cmd
echo.after start cmd /k
cmd /c child.cmd
echo.after cmd /c
pause
exit
Code: Select all
@echo off &setlocal enableDelayedExpansion
set "?=!cmdCmdLine:*/=!"
set "?=!?:~0,1!"
set "?"
if "!?!" == "c" ( exit /b 0 ) else exit 0
Code: Select all
?=c
after start cmd /c
?=k
after start cmd /k
?=c
after cmd /c
Druk op een toets om door te gaan. . .
I should avoid using call though, cmdCmdLine don't work like that !
Thanks again

-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#7
Post
by Ed Dyreen » 11 Nov 2012 00:28
dbenham wrote:Why must you use
START /B /WAIT CHILD.CMD 
I musn't, but this way it works for all cases, even if called

Code: Select all
@echo off &setlocal enableDelayedExpansion
if "%~1" == "" (
call "%~dp0child.cmd"
echo.after call
start "" /low /b "%~f0" /param
exit
)
start "" /low /b /wait "cmd /c" "%~dp0child.cmd" "this and" that
echo.after start cmd /c
start "" /low /b /wait "cmd /k" "%~dp0child.cmd" "this and" that
echo.after start cmd /k
call "%~dp0child.cmd"
echo.after call
pause
exit
Code: Select all
@echo off &setlocal enableDelayedExpansion
echo.
set "cmdLine=!cmdCmdLine:""="!^"
echo.cmdLine=!cmdLine!_
set "cmdType=!cmdLine:*/=!"
set "cmdType=!cmdType:~0,1!"
set "?=!cmdLine:*/%cmdType%=!" &set "fullPathFile=" &for %%? in (
!?:~1!
) do if not defined fullPathFile set "fullPathFile=%%~f?"
echo.if "!fullPathFile!" == "%~f0"
echo.if "!cmdType!" neq "c"
set "exitType=/b" &if "!fullPathFile!" == "%~f0" if "!cmdType!" neq "c" (
set "exitType="
)
echo.exitType=!exitType!_
exit %exitType% 0
Code: Select all
cmdLine=cmd /c "...\tst.cmd" "_
if "...\tst.cmd" == "...\child.CMD"
if "c" neq "c"
exitType=/b_
after call
cmdLine="cmd /c" "...\child.cmd" "this and" that_
if "...\child.CMD" == "...\child.CMD"
if "c" neq "c"
exitType=/b_
after start cmd /c
cmdLine="cmd /k" "...\child.cmd" "this and" that_
if "...\child.CMD" == "...\child.CMD"
if "k" neq "c"
exitType=_
after start cmd /k
cmdLine=C:\WINDOWS\system32\cmd.exe /K "...\tst.cmd" /param_
if "...\tst.cmd" == "...\child.CMD"
if "K" neq "c"
exitType=/b_
after call
Druk op een toets om door te gaan. . .
I'll test tomorrow, but apart from poison chars I don't see why this should fail.