Welcome!

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

SignUp Now!

Replace CTTY in old .BTM

Oct
18
0
Pretty much what it says in the title. I'm rummaging through old .BTMs to see if any are of any use and I came across one that uses CTTY to redirect output to NUL. Other than adding >&NUL to the lines following it, is there any other way of replacing this function?

Thanks
 
I think redirection is the only way. This construction seemed to work in the latest version.

Code:
>&nul (
echo foo
netstat.exe
garbage
echoerr foo
)
 
aha! Yes, that should work. Thanks

I was trying to avoid putting >&Nul on every line and hadn't considered enclosing it all in brackets.
In the end, I decided the specific .BTM, wouldn't be of use to me, but it's nice to know the trick.
 
This also seems to work.

Code:
gosub subroutine >&NUL
echo subroutine returned
quit

:subroutine
echo foo
netstat.exe
garbage
echoerr foo
return
 
This also seems to work.

Code:
gosub subroutine >&NUL
echo subroutine returned
quit

:subroutine
echo foo
netstat.exe
garbage
echoerr foo
return

I prefer the second version. Grouping lines together with parentheses mashes them into a single virtual line, which can have unexpected side effects.
 
I prefer the second version. Grouping lines together with parentheses mashes them into a single virtual line, which can have unexpected side effects.
Yup. I never use parentheses that don't begin and end on the same line. Here's another that seems to work. You can even send some output to CON: (as I did below).

Code:
>&NUL do i=1 to 1
    echo foo > con:
    netstat.exe
    garbage
    echoerr foo
enddo

And (off-topic) you can do the likes of this which I use fairly often.

Code:
do | command | command [...]
...
enddo

I have a "TL" library routine (something like TASKLIST) with this line. %filter, which might be empty, is another pipe.

Code:
do i=0 to %lastline by 7 | d:\gnu\sort %sortargs %filter %@if[defined tail,| TAIL /N %tail,]

And I never use FOR. :smile:
 
Vince, I noticed that in some of your examples above you put redirection commands at the beginning of the line. The TCC help says that they should be placed at the end of the command line. I just experimented and discovered that they, indeed, can be placed at the beginning or the end. Is placing them at the beginning something that is common in other programming environments?
 
I know pretty little about other shells. You can do it in CMD and you can't in PowerShell (I only tried a few simple examples in each). I do it with multi-line DOs; maybe parentheses will help as they do with a one-line DO (didn't try).

Code:
v:\> do i=1 to 2 ( echo foo ) > nul
Usage : DO [n | FOREVER]

v:\> (do i=1 to 2 ( echo foo )) > nul

v:\>

That part of the help might be ancient.
 
Confirmed: with a multiline DO command the redirection works only if placed before the DO. Very interesting. I wonder how piping needs to be handled (but don't have time now to experiment).
 
Vince, I noticed that in some of your examples above you put redirection commands at the beginning of the line. The TCC help says that they should be placed at the end of the command line. I just experimented and discovered that they, indeed, can be placed at the beginning or the end. Is placing them at the beginning something that is common in other programming environments?
You mean, other shell languages? It depends on the language.

Generally in Linux/Unix BASH or TCSH the redirect is at the end of the line, but I bet I could find a counterexample or two. Every one of these languages has its own (sometimes bizarre) quirks. One of the reasons I like TCmd so much is that -- by and large -- it ISN'T quirky. (Or if it is, it is transparent to me, i.e. things generally work like I'd expect.)

(SImilarly, I really, Really, REALLY hate PowerShell. Yes, it's powerful. But I don't like writing in a language where I have to refer to the .NET documentation.... For. Every. Single. Line! )
 
IIRC, with some constructs (notably DO) it works at the beginning and not at the end. I have no clue about other shells.
 
FWIW, pipes work at the end (sort of).

Code:
do i=1 to 2 | grep foo
    echo foo
    echo bar
enddo
 
Vince, what's with this?

Code:
[TCC35.00.14 | C:\] do i = 1 to 3 ( echo i = %i )
i = 1
i = 2
i = 3

[TCC35.00.14 | C:\] > junk.txt do i = 1 to 3 ( echo i = %i )

[TCC35.00.14 | C:\] type junk.txt
i = 4
i = 4
i = 4
 
I can't say exactly what happened. Single line DOs seem different. With a single line DO you can redirect at the end but you need a command group (I do that all the time).

Code:
d:\data\tcclibrary> (do i = 1 to 3 ( echo i = %i )) > junk.txt

d:\data\tcclibrary> type junk.txt
i = 1
i = 2
i = 3

A command group doesnt' help your example though similar constructions do work.

Code:
d:\data\tcclibrary> >junk.txt (do i = 1 to 3 ( echo i = %i ))

d:\data\tcclibrary> type junk.txt
i = 4
i = 4
i = 4

d:\data\tcclibrary> >junk.txt (echo foo)

d:\data\tcclibrary> type junk.txt
foo
 
Back
Top