tee command cancels colors

May 23, 2010
36
1
Seattle
Code:
[C:\batch]type foo.btm
color red on bri yel
echo plain echo
echo to file > file
echo pipe to sort | sort /o sortfile
echo pipe to tee | tee teefile
echo my colors were canceled

[C:\batch]foo
color red on bri yel
echo plain echo
plain echo
echo to file > file
echo pipe to sort
echo pipe to tee
pipe to tee
echo my colors were canceled
my colors were canceled

[C:\batch]
colortee.jpg


It's a bit of a nuisance, as I'm putting out error messages both to the console and to an error file. But I can work around it by just doing two separate echo statements.
 

rconn

Administrator
Staff member
May 14, 2008
12,404
152
What version of TCMD and Windows are you running?

Do you have ANSI Colors enabled in TCMD.INI? (See OPTION / Windows).

TCMD doesn't control colors, that's done in the console session (TCC in this case) and simply mirrored in TCMD. And in the console session, TCC doesn't control the display of characters & colors, that's done by Windows. Win 10 & 11 display colors using ANSI, so you need to set that option in TCC.
 
May 20, 2008
11,529
102
Syracuse, NY, USA
I think this has to do with another TCC being started to handle the pipe. I believe that under some circumstances, TCC momentarily takes the console out of VT mode (and with the new console, I think color attributes are handled internally with VT sequences). The consequences of piped instances and VT mode have been discussed a little but nothing has come of it. This does it too.

1635383773856.png


So does this.

1635383927413.png
 
May 23, 2010
36
1
Seattle
TCmd 28.01.14 x64
Win 10 Pro 21H1
TCmd.INI:
[TakeCommand] ANSI=No
[4NT] ANSI=Yes
In the windowed options inside TCC, the ANSI box is checked.

I tried changing that one setting in TCmd.INI to Yes. Made no difference.
 
May 23, 2010
36
1
Seattle
Interesting. These two command sets produce different results:
Code:
color bri yel on gre
echo foo | sort /o trash & echo foo
Code:
color bri yel on gre
echo foo | sort /o trash
echo foo
The first one changes the output color; the second does not.
 
Aug 9, 2009
237
1
With a comment like that it's unlikely you're be getting any free help in the future from one of the most knowledgeable users on this site.

I'm offended by it
 
May 23, 2010
36
1
Seattle
I'm really sorry you feel that way, Kachupp. I fully realize the esteem in which Vince is held here, and I feel honored that he has (and takes!) the time to deal with piddling little posts like mine. After a 50-year career in IT, including plenty of nights spent at work with a sleeping bag, I know how it feels to have precious little time for other activities. And I didn't mind a bit, being on the receiving end of similar comments.

Vince, if you took offense, I apologize.

Bret Sutton
 
  • Like
Reactions: TEA-Time
Jan 12, 2014
436
7
Switzerland, SO
I really don't think that old coot meant that offended, that was ironical, that's all.

But I know, sometimes it's difficult to see the ironical point in internet (postings) or something like that.

Take it easy, Kachupp.
 

rconn

Administrator
Staff member
May 14, 2008
12,404
152
A command like "color yel on gre" doesn't use the Win 10/11 ANSI; it simply sets the default console text attribute via the SetConsoleTextAttribute command. This will be overwritten by the next ANSI sequence (e.g., in the prompt).

If you have a default output color set in OPTION / Windows (the StdColor directive in TCMD.INI), TCC will call SetConsoleTextAttribute when it starts (including in a child pipe process). The only other place TCC will set the colors is if you specify the /Txx startup option.
 
May 20, 2008
11,529
102
Syracuse, NY, USA
WAD - in the first instance, TCC sees there's a command following SORT (which SORT won't know how to handle), so it has to call a child TCC process to run SORT and then the ECHO FOO:

Code:
tcc /c sort /o trash & echo foo
Hmmm! I have always thought that an unqualified '&' was enough to signal that what comes after it is not part of the command before it. In fact (being quite naive) I have thought that one of the first things done was to separate a compound command at the command separators.
 

rconn

Administrator
Staff member
May 14, 2008
12,404
152
Hmmm! I have always thought that an unqualified '&' was enough to signal that what comes after it is not part of the command before it. In fact (being quite naive) I have thought that one of the first things done was to separate a compound command at the command separators.

Well, that'd be (1) incompatible with every other command interpreter, and (2) break almost every batch file that uses pipes. Or compound commands. Or conditional commands.

In your simple (but not real-world useful) example, the "echo foo" could reasonably be executed at the parent process level, not in the child pipe process. (Though there isn't any benefit in trying to pass it back to the parent.) But what about:

Code:
cmd1 | cmd2 | cmd3

Cmd3 can't be executed by cmd1, because (1) cmd2 already ate all the output, and (2) cmd3 expects the output to be coming from cmd2.

Similar problems exist with && and || - they need to be the result of the preceding command, not the parent.

So what you're asking is for the parser to automagically determine whether anything on the right side of a separator (&, &&, |, or ||) *might* not have any interaction with the command immediately preceding it. Without knowing what the command (especially an external) is going to do. And what would be the benefit - not having to worry about whether you redefined colors just before executing a pipe?

The current (correct!) behavior is how it's worked for the last 25 years or so. If you want everything executed in the same shell, use DOS pipes.
 
Aug 9, 2009
237
1
I'm really sorry you feel that way, Kachupp. I fully realize the esteem in which Vince is held here, and I feel honored that he has (and takes!) the time to deal with piddling little posts like mine. After a 50-year career in IT, including plenty of nights spent at work with a sleeping bag, I know how it feels to have precious little time for other activities. And I didn't mind a bit, being on the receiving end of similar comments.

Vince, if you took offense, I apologize.

Bret Sutton
All good Bret. The condescending tones are not!
This isn't appropriate forum for further comments. Anyway I'm over it.
 
May 20, 2008
11,529
102
Syracuse, NY, USA
You can workaround this difficulty by using in-process pipes. It also works around other things getting lost when a pipe instance of TCC momentarily removes the console's ENABLE_VIRTUAL_TERMINAL_PROCESSING mode (like tabstop settings and underlining). Much to my surprise, and contrary to the help, in-process pipes seem, almost always, to be faster than out-of-process pipes, sometimes a lot faster. Here are a couple timing comparisons. If others compare times, I'd like to hear the results.

Code:
v:\> timer (do i=1 to 100 (echo foo | ffind /k /m /t"bar"))
Timer 1 on: 18:08:48
Timer 1 off: 18:08:57  Elapsed: 0:00:09.544

v:\> timer (do i=1 to 100 (echo foo |! ffind /k /m /t"bar"))
Timer 1 on: 18:09:03
Timer 1 off: 18:09:08  Elapsed: 0:00:04.675

v:\> timer (do i=1 to 100 (echo foo | findstr bar))
Timer 1 on: 18:09:35
Timer 1 off: 18:09:42  Elapsed: 0:00:06.422

v:\> timer (do i=1 to 100 (echo foo |! findstr bar))
Timer 1 on: 18:09:47
Timer 1 off: 18:09:52  Elapsed: 0:00:05.200

Here's a pic of it working where it failed with a normal pipe..

1635891814271.png
 
Code:
e:\utils>timer (do i=1 to 100 (echo foo | ffind /k /m /t"bar"))
Timer 1 on: 19:58:20
Timer 1 off: 19:58:49  Elapsed: 0:00:29.367

e:\utils>timer (do i=1 to 100 (echo foo |! ffind /k /m /t"bar"))
Timer 1 on: 19:59:25
Timer 1 off: 19:59:29  Elapsed: 0:00:04.186

e:\utils>timer (do i=1 to 100 (echo foo | findstr bar))
Timer 1 on: 19:59:42
Timer 1 off: 19:59:50  Elapsed: 0:00:08.108

e:\utils>timer (do i=1 to 100 (echo foo |! findstr bar))
Timer 1 on: 20:00:02
Timer 1 off: 20:00:10  Elapsed: 0:00:08.077

Joe
Code:
     _x64: 1
   _admin: 1
_elevated: 1

TCC  28.02.15 x64   Windows 10 [Version 10.0.19043.1288]

1635897891506.png
 
May 20, 2008
11,529
102
Syracuse, NY, USA
That first one is outrageous, Joe Caverly. Did you try it a second time?

And what the heck do you do with 128 GB RAM?
 
That first one is outrageous, Joe Caverly. Did you try it a second time?

And what the heck do you do with 128 GB RAM?
Hi @vefatica,
I just re-ran them;
Code:
e:\utils>timer (do i=1 to 100 (echo foo | ffind /k /m /t"bar"))
Timer 1 on:  8:02:39
Timer 1 off:  8:03:11  Elapsed: 0:00:31.724

e:\utils>timer (do i=1 to 100 (echo foo |! ffind /k /m /t"bar"))
Timer 1 on:  8:05:42
Timer 1 off:  8:05:47  Elapsed: 0:00:04.524

e:\utils>timer (do i=1 to 100 (echo foo | findstr bar))
Timer 1 on:  8:05:57
Timer 1 off:  8:06:05  Elapsed: 0:00:08.325

e:\utils>timer (do i=1 to 100 (echo foo |! findstr bar))
Timer 1 on:  8:06:15
Timer 1 off:  8:06:24  Elapsed: 0:00:08.498

As for the 128 GB RAM, I'm using it to explore the MilkyWay, for RAMDisks, for Virtual Machines, and for SandBoxes.

Joe
 
May 20, 2008
11,529
102
Syracuse, NY, USA
I think that first test is the only one of the four that starts new TCCs. It's very slow (compared to here). I'll bet you're doing a lot in TCSTART.
 
I think that first test is the only one of the four that starts new TCCs. It's very slow (compared to here). I'll bet you're doing a lot in TCSTART.
I am indeed doing a lot in TCSTART.

When I start TCC.EXE with the /i option;
Code:
c:\program files\jpsoft\tcmd28>tcc.exe /i

TCC  28.02.15 x64   Windows 10 [Version 10.0.19043.1288]
Copyright 2021 JP Software Inc.  All Rights Reserved
Registered to DESKTOP-H2JFFTF

c:\program files\jpsoft\tcmd28>@timer (do i=1 to 100 (echo foo | ffind /k /m /t"bar"))
Timer 1 on: 11:19:01
Timer 1 off: 11:19:45  Elapsed: 0:00:43.229

c:\program files\jpsoft\tcmd28>@timer (do i=1 to 100 (echo foo | ffind /k /m /t"bar"))
Timer 1 on: 11:21:02
Timer 1 off: 11:21:46  Elapsed: 0:00:44.049
...TCSTART.BTM is not loaded, and it takes longer?

With TCSTART.BTM;
Code:
c:\program files\jpsoft\tcmd28>tcc.exe /i

TCC  28.02.15 x64   Windows 10 [Version 10.0.19043.1288]
Copyright 2021 JP Software Inc.  All Rights Reserved
Registered to DESKTOP-H2JFFTF

c:\program files\jpsoft\tcmd28>@exit

c:\program files\jpsoft\tcmd28>timer (do i=1 to 100 (echo foo | ffind /k /m /t"bar"))
Timer 1 on: 11:25:26
Timer 1 off: 11:26:01  Elapsed: 0:00:34.705
...it's faster?

Note well, that the preceeding was run from TCC.EXE inside TCMD.EXE

When I run in a stand alone TCC.EXE window, results are similar, if not the same.

Joe
 
Similar threads
Thread starter Title Forum Replies Date
C TEE command appending null characters to output Support 6
D Why is the TEE command 120 times slower? Support 10
David McClelland TEE command puts it's output file in c:\ Support 4
A How to? TEE - duplicate output to STDERR Support 3
Peter Murschall TEE cannot handle Unicode output Support 2
vefatica TEE /A adds newline? Support 2
vefatica Debug messages from TEE? Support 3
Joe Caverly Problem with TEE in v22 Support 2
Roedy problem with tee Support 2
krischik WAD Tee printing Chinese characters Support 7
J TEE Problem Support 11
vefatica WAD TEE adds newlines Support 4
A How to? Use TEE with .NET output Support 6
D WAD Multiple TEE causese weird variable scoping? Support 7
S Tee? Support 9
Z CMDDebug - TCC unknown command Support 2
F Edit command Support 1
rconn News Take Command / TCC / CMDebug / TCC-RT 28.02.17 Support 0
old coot LEAVE appears to affect command-line arguments Support 11
J VDESKTOP command Support 3
Dmitry L. Kobyakov How to? How to remove the record of the old version of the Take Command? Support 9
D Can alias pass parameters to for command? Support 3
samintz How to? Search for %(command) in Help? Support 1
T VIEW only works from command line Support 14
rconn News Take Command / TCC / CMDebug / TCC-RT v28 Released Support 0
T Take Command 28: Lua reports version 5.4.0 (5.4.3 expected) [SOLVED] Support 1
Jay Sage WAD Possible Bug With OPTION Command With @FILE Support 5
rconn News Take Command / TCC / CMDebug / TCC-RT 27.01.24 uploaded Support 0
J Take command does not start on Windows 10 Support 3
vefatica `Back quotes` - command line vs. batch file Support 5
Jay Sage WAD Failure of Alias Command with /Z Option Support 14
Phileosophos Is there any way to open the Take Command options dialog from the command line? Support 8
Phileosophos Command-line Editing Shortkeys That Fail Support 6
fpefpe How to? free (internal) command Support 0
rconn News Take Command / TCC / CMDebug / TCC-RT 27.01.23 uploaded Support 0
T How to? retain command history across reboot? Support 6
rconn News Take Command / TCC / CMDebug / TCC-RT v27.01 Build 22 Uploaded Support 0
Jay Sage Bug With Flow Control and/or Command Grouping Support 2
GermanDirk How to? EVENTLOG Command with simple User Rights not functional Support 4
Jay Sage Take Command Is Too Fast! Support 4
Jay Sage Comparison of IF with Command Group and IFF Support 6
D Open Windows 10 Photos app from command line Support 11
rconn News Take Command / TCC / CMDebug / TCC-RT 27.0.21 uploaded Support 0
rconn News Take Command / TCC / CMDebug / TCC-RT 27.0.20 uploaded Support 0
U Can not get/start Take Command gui Support 1
rconn News Take Command / TCC / CMDebug / TCC-RT 27.0.19 Support 0
S Increasing Font Point Size in Command Tabs Support 2
mfarah Fixed The DATE command produces the wrong error message. Support 1
vefatica Command name mix-up Support 3
FreezerBurnt "Missing SETLOCAL" when initializing Visual Studio Command Prompt. Support 9

Similar threads