Can't CLS during redirection - New bug or known?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
T3RRY
Posts: 250
Joined: 06 May 2020 10:14

Can't CLS during redirection - New bug or known?

#1 Post by T3RRY » 21 Jan 2023 00:10

Not something I've encountered before, but found myself wanting to clear the screen between outputs during a redirected block, and CLS wouldn't work.

I did a bit of searching, couldn't find mention of the problem here previously.
I believe the issue only occurs if it's STDOUT being redirected.
Flipping the STDERR / STDOUT streams and Redirecting the STDERR handle resolves the issue

Code: Select all

@Echo off

1>"%~dp0example.tmp" (
	1>con Echo(See this?
	Echo(Can't see this, it's in the file
	CLS
	1>con Echo(Shouldn't see that but do.
)

Pause

1>&2 2>>"%~dp0example.tmp" (
	2>con Echo(You won't see this.
	CLS
	1>&2 Echo(This will go to file
	2>con Echo(You Didn't see that.
)
Title close notepad to quit
notepad "%~dp0example.tmp"

Del "%~dp0example.tmp"


Aacini
Expert
Posts: 1913
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Can't CLS during redirection - New bug or known?

#2 Post by Aacini » 21 Jan 2023 01:20

When a CLS command is redirected to a disk file, it output an ASCII 12 character, Ctrl-L called Form Feed that in most printers cause to eject current page and jump to a new page. This is a rather logical "conversion" of screen CLS command to a (paper) text file.

This conversion is well-known, but I don't remember right now where you could review it...

Antonio

T3RRY
Posts: 250
Joined: 06 May 2020 10:14

Re: Can't CLS during redirection - New bug or known?

#3 Post by T3RRY » 21 Jan 2023 03:58

Aacini wrote:
21 Jan 2023 01:20
When a CLS command is redirected to a disk file, it output an ASCII 12 character, Ctrl-L called Form Feed that in most printers cause to eject current page and jump to a new page. This is a rather logical "conversion" of screen CLS command to a (paper) text file.

This conversion is well-known, but I don't remember right now where you could review it...

Antonio
Thanks for the speedy reply Antonio, I had also tried redirecting the cls to con with no luck - hadn't thought to view the output in a robust text editor however. Something I'll remember for next time.

Knowing the Form Feed issue helped me find the orginal post it was discussed in. viewtopic.php?p=13680#p13680

Post Reply