Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Variable not expanding with detach

Nov
3
0
I'm using
TCC 13.01.31 x64 Windows Vista [Version 6.0.6002]

This batch file

REM tcc_ex.bat
set myp=d:
%myp%\bat\xn.bat &

doesn't work, because the variable %myp is not expanded:

s:\>tcc_ex
set myp=d:
DETACH %myp%\bat\xn.bat
The process ID is 6340

But if the "&" is removed then the resulting batch file

REM tcc_ex.bat
set myp=d:
%myp%\bat\xn.bat

calls d:\bat\xn.bat and works as expected.
(This is a simplified example.)

Is this a bug?

---Nick Higham
 
> This batch file
>
> REM tcc_ex.bat
> set myp=d:
> %myp%\bat\xn.bat &
>
> doesn't work, because the variable %myp is not expanded:
>
> s:\>tcc_ex
> set myp=d:
> DETACH %myp%\bat\xn.bat
> The process ID is 6340

A batch file by itself cannot be detached, because there's nothing to
execute it. So what's happening is that this is being converted to
something like "c:\program files\jpsoft\tcmd13\tcc.exe /c %myp%\bat\xn.bat",
and the variable expansion is going to occur in the detached process, not in
the parent process.
 
Thanks, Rex.
I introduced the batch file in trying to simplify the example, but ended up obfuscating it. My actual example has

%myp%\emacs-23.3\bin\emacsclientw.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 &

as the line causing the unexpanded %myp%, with a call to an executable.
At the moment I'm having to use instead the long-winded

iff (%myp%)==(c:) then
c:\emacs-23.3\bin\emacsclientw.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 &
elseiff (%myp%)==(e:)
e:\emacs-23.3\bin\emacsclientw.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 &
endiff

Any thoughts on this would be appreciated.

---Nick Higham
 
> I introduced the batch file in trying to simplify the example, but ended
> up obfuscating it. My actual example has
>
> %myp%\emacs-23.3\bin\emacsclientw.exe %1 %2 %3 %4 %5 %6 %7 %8 %9
> %10 &
>
> as the line causing the unexpanded %myp%, with a call to an executable.

A line with a trailing '&' gets a "DETACH " prefixed to it. And the parser
does not do *any* variable expansion on a DETACH command line (by design,
for several reasons). If you want variable expansion on a DETACH command,
you need to pass it a command processor (TCC or CMD) to do the expansion.

DETACH is also only intended to be used by character-mode apps -- is your
"emacsclientw.exe" a console app or Windows app?
 

Similar threads

Back
Top