CLS (clear) a single line?

Viewed 25492

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?

4 Answers

An alternative quick&dirty method of moving the cursor via TIMEOUT:

@echo off
<nul set/p"=5 seconds till i close..."
timeout /t 5 /nobreak >con
echo(i'm closing now...[REPLACE this with lots of spaces]
exit /b

Related