issue: redirecting GOSUB output

May 31, 2008
382
2
The following batch file shows an issue with "gosub label > file"; TCC prints a command log to the file instead of printing the output of the labeled sub-routine. The first "gosub EMIT1" is sufficient to show the issue, the rest of the script simply tries variations of gosub syntax.
Although I also tried - to no avail - enclosing gosub within brackets the help file explicitly says that gosub can't be used in a command group. It doesn't say (I couldn'd find) that gosub can't be redirected.
I tested TCC 14.00.31, TCC 13.04.63, TCCLE 13.04.63 on WinXP SP3 x32 and Win7 SP1 x32. All tested versions are affected. If this indeed turns out to be a bug to be fixed, would you please fix TCCLE as well? Thank you.
issue.btm:
Code:
setlocal
gosub EMIT1 a1 > issue1.txt
call :EMIT2 a2 > issue2.txt
gosub "%_batchname" EMIT1 a3 > issue3.txt
type issue1.txt
echo ---
type issue2.txt
echo ===
type issue3.txt
echo ***
endlocal
quit
:EMIT1 [a]
rem gosub [batchname] EMIT1 > FILE prints command log to FILE
rem istead of printing the output of EMIT1
echo (%a) foo
return
:EMIT2 [a]
rem CMD-compatible subroutine
rem same issue as gosub EMIT1
echo (%a) bar
quit
output:
Code:
V:\temp>issue.btm
setlocal
gosub EMIT1 a1 > issue1.txt
call :EMIT2 a2 > issue2.txt
gosub "V:\temp\issue.btm" EMIT1 a3 > issue3.txt
type issue1.txt
rem gosub [batchname] EMIT1 > FILE prints command log to FILE
rem istead of printing the output of EMIT1
echo (a1) foo
(a1) foo
return
echo ---
---
type issue2.txt
rem CMD-compatible subroutine
rem same issue as gosub EMIT1
echo () bar
() bar
quit
echo ===
===
type issue3.txt
rem gosub [batchname] EMIT1 > FILE prints command log to FILE
rem istead of printing the output of EMIT1
echo (a3) foo
(a3) foo
return
echo ***
***
endlocal
quit
 
May 20, 2008
11,411
99
Syracuse, NY, USA
I have BatchEcho off (OPTION). And I don't get the commands echoed in the files. I also took the TYPEs and ECHOs out of the BTM's main section because they confused me. All looks good except that in the test that uses CALL, the argument "a2" is either not passed or not used. Is that expected? The help shows CALL with a label and parameters.
Code:
v:\> type issue.btm
setlocal
gosub EMIT1 a1 > issue1.txt
call :EMIT2 a2 > issue2.txt
gosub "%_batchname" EMIT1 a3 > issue3.txt
endlocal
quit
:EMIT1 [a]
echo (%a) foo
return
:EMIT2 [a]
echo (%a) bar
quit
 
v:\> issue.btm
 
v:\> type issue1.txt
(a1) foo
 
v:\> type issue2.txt
() bar                            <===== there's no "a2" here?
 
v:\> type issue3.txt
(a3) foo
 
May 31, 2008
382
2
If I add the missing "@echo off" to the beginning of your batch file, I get:

(a1) foo
---
() bar
===
(a3) foo
***

which seems to be what you're looking for.
Why missing? Is it mandatory to @echo off a batch file?
I don't usually need to @echo off a batch file in order to redirect output from DO like in the test script below
Code:
@echo on
(do i in /L a b c (echo %i)) > clip:
type clip:
output:
Code:
M:\>test.btm
(do i in /L a b c (echo %i)) > clip:
type clip:
a
b
c
Why is gosub different?
 
Aug 2, 2011
258
4
Berlin, Germany
Hi, by reading this thread I learned that I can use redirection with "call :label" or "gosub"!
I'm using 4dos for quiet a while, but I never would have that idea by myself :rolleyes:
Sometimes I can't use my eyes. *
Thanks.

* is this a suitable collocation for beeing blind?
 
May 20, 2008
11,411
99
Syracuse, NY, USA
Why missing? Is it mandatory to @echo off a batch file?
I don't usually need to @echo off a batch file in order to redirect output from DO like in the test script below
Code:
@echo on
(do i in /L a b c (echo %i)) > clip:
type clip:
output:
Code:
M:\>test.btm
(do i in /L a b c (echo %i)) > clip:
type clip:
a
b
c
Why is gosub different?
They don't even seem related. In the DO example, the line is echoed (because ECHO is ON) and then it's executed; you have not redirected the batch-echoing. In the GOSUB example you have redirected the whatever output the gosub produces (which includes the batch-echoing itself). It seems right to me.
 
Jan 19, 2011
604
14
Norman, OK
Hi, by reading this thread I learned that I can use redirection with "call :label" or "gosub"!
I also have a lot of "WOW! I didn't know that! That's cool!" moments when reading the forum.
 
Similar threads
Thread starter Title Forum Replies Date
cgunhouse TCToolBar /W Issue Support 2
G v28 Display Issue Support 7
Jay Sage Issue with CD_ENTER Alias Support 37
Jay Sage Issue with CD_LEAVE Alias Support 3
fpefpe How to? issue with % and evaluation Support 5
cgunhouse Standard User Account Issue Support 2
samintz WAD Display wrapping issue Support 5
M TCC color issue in ConEmu Support 4
samintz Timer issue Support 4
Alpengreis Documentation Minor issue in help file for view /E Support 1
samintz WAD ANSI issue Support 3
D TCSTART issue after reinstallation Support 14
A Documentation [Help file] OPTION "//" synopsis formatting issue Support 0
Chen Touboul Overtyping issue - i press the Insert key, help till press enter for new line in TCC Support 2
Y TCC and Cmder imcompatibility issue Support 7
M Another possibly strange remote registry issue Support 5
T WAD bpokestr issue Support 5
D High-DPI Scaling issue Support 1
S CMDebug 22 issue with del command Support 1
cgunhouse Foldermonitor Issue Support 7
samintz Build 38 Install issue Support 5
rps WAD Setlocal issue Support 4
Luiz Rodrigues Issue with Maven Support 1
Seven Update / install issue with 20.0.20.10.32 take command Support 7
Fross WebDav Drive Mapping Issue Support 19
D Upgrade issue Support 3
Fross V20b8 Everything Issue Support 5
T TCC display issue Support 1
cgunhouse _logfile Issue Support 5
T Fixed Querybox issue Support 1
cgunhouse Fixed Share Memory Issue Support 5
cgunhouse Foldermonitor with "/E" Option Issue Support 6
Fross TabComplete Argument Issue Support 1
fpefpe How to? Stange start up issue Support 1
C cosmetic issue with LIST's (I) Support 9
jbarnes1967 TC 18.00 x64 issue with lua io.popen() Support 2
D How to? Wildcards as sets - looping issue with FOR and REN Support 7
T WAD Free issue Support 6
R Fixed v17.0.54 Tab->COMSPEC Dialog Box Issue Support 2
R Minor Cosmetic Issue in Take Command Window Support 2
cgunhouse One line IFF ... Then ... Else ... EndIFF Statement issue in V17 Support 13
cgunhouse IFTP Path Issue in V17 - Fixed Support 7
S BDEBUGGER issue Support 9
cgunhouse @ISPROC Issue Support 15
cgunhouse TCMD.INI Issue Support 7
T Fixed multi-line alias issue Support 13
R WAD issue with filename completion with system and hidden files Support 8
D Strange issue with FOR loop Support 15
C Install Issue with 3rd Party Privelege Escalation Support 2
W Button command issue Support 5

Similar threads