Variable not expanding with detach

Nov 26, 2011
3
0
Manchester, UK
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
 

rconn

Administrator
Staff member
May 14, 2008
12,344
149
> 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.
 
Nov 26, 2011
3
0
Manchester, UK
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
 

rconn

Administrator
Staff member
May 14, 2008
12,344
149
> 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
Thread starter Title Forum Replies Date
rfaquino WAD Apparently a bug when expanding environment variable %ProgramFiles(x86) Support 2
D Parsing an array variable to an array does not work Support 5
sully9 How to? Unexpected %DATE% CMD variable format (vs DATE /T format) in CMDebug Support 1
P Inserting string into a variable. Support 3
vefatica Setting array variable ignores leading spaces (and @execarray doesn't) Support 4
Joe Caverly Set a batch variable (%1 - %n) when TCC is executing a batch file Support 5
R Difference between TCC and CMD: variable names with hyphens Support 4
Joe Caverly Get a variable type Support 2
M How to set Path variable for non-executable file extensions in 4DOS Support 8
rps For loop internal %_for_files variable? Support 2
A How to safely print variable's value without quotes? Support 9
vefatica Array name in a variable? Support 3
nikbackm TCC 20 variable expansion bug Support 6
X How to set %_INIREAD result to variable Support 5
Charles Dye _USBS variable Support 2
BeechComer Debugger: how to set %1 variable? Support 3
Mordachai Variable followed by function constantly failing... Support 5
T Variable indirection for arrays Support 1
Mike Hall Unexpected "Variable loop" in IF condition Support 10
vefatica If there's no PATH variable ... Support 5
C Maximum length for a variable Support 8
D WAD Internal variable _cpu is undefined Support 2
fpefpe How to? Global variable set /v Support 4
I Change value of a variable while debugging Support 3
I "IF" command in a variable does not expand redirection variable name Support 0
J Variable setting regression in tcc17 ? Support 5
Jay Sage WAD Variable _LOGFILE Not Working Support 2
D Fixed Change in behavior of variable expansion between 16 and 17 Support 3
rps Fixed Using last argument variable ! Support 5
Jay Sage Brackets Around Variable Names Support 11
D Internal variable _tctabs within TCExit Support 9
vefatica WAD Nested variable expansion in PDIR's @function[*]? Support 13
J Set environment variable from stdout of command Support 3
nickles Passing a variable to a command w/o adding it to the local environment Support 7
nickles WAD Variable name gets changed within FOR loop Support 2
nikbackm FUNCTION with variable number of arguments Support 17
S WAD %_do_errors does not report errors when loop control variable type is not directory entry Support 1
B WAD environment variable in TCC.exe Support 2
Frank watch an array variable in ide/bdebugger Support 2
vefatica Conditional expressions in a variable? Support 2
CWBillow UNSET a Variable Support 7
M Updating environment variable from C++ fails erratically in version 14... Support 57
Frank problem with environment variable x86 vs. x64 Support 2
Charles Dye Unbalanced parentheses in variable expansion Support 12
D WAD Multiple TEE causese weird variable scoping? Support 7
fpefpe volatile variable Support 5
T Bug in variable expansion Support 4
S New "home" variable parsing issue Support 1
H variable programfiles(x86) loses space Support 1
nikbackm Command line evaluation question - variable inside parenthesis Support 7

Similar threads