detach caveat

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
May 31, 2008
If a batch file executes
DETACH "%variable%"
I can see with Process Explorer that TCC starts
C:\TCMD\tcc.exe /c "%variable%"
where %variable% is left for the detached process to expand.

The caveat is that if %variable% is an expression that includes %_batchname then tcc.exe /c will most likely not expand it as intended, since %_batchname is undefined at that point.

I'm sure Rex has a good reason for designing DETACH this way; so the work-around for me is to
SET bn=%_batchname
DETACH "%bn%"

as illustrated in the following script (unREM the second DETACH line to see the effect)
iff .%1 == .DETACHED then
  OSD /time=3 /hcenter /vcenter running %_pid detached
  echo detaching "%_batchname"
  detach "%_batchname" DETACHED & rem starts nothing
  set bn=%_batchname
  REM detach "%bn%" DETACHED & rem starts %_batchname