Alex Rivera | Logout

CLS (clear) a single line?

Asked 2012-08-15T15:24:40.260
10

Is there any way to CLS a single line of output? I don't believe there are any switches for CLS, so maybe a better question would be:

Is there any way to

  1. retain all previous output for re-use?
    or
  2. capture currently displayed output (like you can by marking and copying)?

I'm just trying to make my scripts a little more user-friendly by having real-time feedback / information, instead of multiple lines with slight changes. The only way I can think of doing this, though, is like this:

@echo off
goto Prep

:Prep
    SET count=5
    SET genericMessage=This window will close

    goto Output

:Output
    IF NOT %count% == -1 (
        cls
        IF %count% == 0 (
            echo %genericMessage% now.
        ) ELSE (
            echo %genericMessage% in %count% seconds.
        )
        SET /A count=%count% - 1
        ping localhost -n 2 >nul
        goto Output
    ) ELSE (
        exit
    )

So, you get this:

enter image description here

The problem with this, though, is that CLS erases all output, when I only want to refresh one line by erasing and re-outputting it.

Anyone have any ideas?

Edit
Report

1 Answer

4

Unfortunately, there is no native command or utility that repositions your cursor in a Windows command line console.

You will need a 3rd party utility.

Aacini posted a free CursorPos.exe utility on DOSTips. The CurorPos.exe "source" is given as Hex digits. To use the source you will need the HexToBin.bat "compiler".

Browse both threads and you will find a number of utilities you may find useful.

answered 2012-08-15T16:00:36.170

Your Answer