Welcome!

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

SignUp Now!

Difference Between ECHO and ECHOERR

Jun
1,092
48
I stumbled across this difference in the way ANSI sequences are processed by ECHO and ECHOERR. With ECHO I can write a line and then use ESC [ A to move the cursor up one line and overwrite the previous text. That does not work with ECHOERR.

Code:
>echo. & do i = 1 to 5 (echo ^e[A %@format[3,%i] of 5 & delay 1 )
   5 of 5

>echoerr. & do i = 1 to 5 (echoerr ^e[A %@format[3,%i] of 5 & delay 1 )
   1 of 5
   2 of 5
   3 of 5
   4 of 5
   5 of 5

If I use ECHOS and ECHOSERR and ^r to return to the beginning of the line, both work.

Code:
>do i = 1 to 5 (echoserr ^r %@format[3,%i] of 5 & delay 1 )
   5 of 5
>do i = 1 to 5 (echos ^r %@format[3,%i] of 5 & delay 1 )
   5 of 5

The equivalent ANSI sequence for "cursor to beginning of line" also works for both, so the problem is not with all ANSI sequences and seems to be only for ECHOERR, not ECHOSERR.

Code:
>do i = 1 to 5 (echos ^e[G %@format[3,%i] of 5 & delay 1 )
   5 of 5
>do i = 1 to 5 (echoserr ^e[G %@format[3,%i] of 5 & delay 1 )
   5 of 5
 
ECHOERR returns you to where the cursor was; ECHO does not. Compare these (several times each).

Code:
v:\> echoerr ^e[1;1Hfoo
v:\> echo ^e[1;1Hfoo
 
I stumbled across this difference in the way ANSI sequences are processed by ECHO and ECHOERR. With ECHO I can write a line and then use ESC [ A to move the cursor up one line and overwrite the previous text. That does not work with ECHOERR.

Code:
>echo. & do i = 1 to 5 (echo ^e[A %@format[3,%i] of 5 & delay 1 )
   5 of 5

>echoerr. & do i = 1 to 5 (echoerr ^e[A %@format[3,%i] of 5 & delay 1 )
   1 of 5
   2 of 5
   3 of 5
   4 of 5
   5 of 5

Not reproducible here with TCC in a stand-alone console, in a Take Command tab window, or in Windows Terminal.

What is your environment and version(s)?
 
Reproduces here (all three terminals)..

Code:
v:\> echo. & do i = 1 to 5 (echo ^e[A %@format[3,%i] of 5 & delay 1 )
   5 of 5

v:\> echoerr. & do i = 1 to 5 (echoerr ^e[A %@format[3,%i] of 5 & delay 1 )
   1 of 5
   2 of 5
   3 of 5
   4 of 5
   5 of 5

TCC 36.50.65 x64 (d:\tc36\tcc.exe)
Microsoft Windows 11 Pro for Workstations
10.0.26200.8655 (25H2)
WindowsTerminal 1.24.2605.12001 (1.24.1321.0) (store)
 
Those do exactly the same thing here (TCC console, TCMD, WT). What are you seeing?
Maybe that wasn't the best test. Try these, each in a clear viewport. ECHOERR moves the cursor bach to where it was; ECHO doesn't.

1782744324622.webp


1782744382207.webp
 
Reproduces here (all three terminals)..

Code:
v:\> echo. & do i = 1 to 5 (echo ^e[A %@format[3,%i] of 5 & delay 1 )
   5 of 5

v:\> echoerr. & do i = 1 to 5 (echoerr ^e[A %@format[3,%i] of 5 & delay 1 )
   1 of 5
   2 of 5
   3 of 5
   4 of 5
   5 of 5

TCC 36.50.65 x64 (d:\tc36\tcc.exe)
Microsoft Windows 11 Pro for Workstations
10.0.26200.8655 (25H2)
WindowsTerminal 1.24.2605.12001 (1.24.1321.0) (store)

Not reproducible on three systems here (Win 10 & 11, console, TCMD, WT).

Try it with your TCMD.INI & plugins disabled.
 
Back
Top