How to replace value in same line in DOS window.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
level3
Posts: 4
Joined: 16 Apr 2013 03:47

How to replace value in same line in DOS window.

#1 Post by level3 » 16 Apr 2013 03:57

I have a batch file which automatically restart vlc.exe if the app crashes. I am also counting the number of times it crashes.

my current coding output is like:


VLC crashed for : 0 times.
VLC crashed for : 1 times.
VLC crashed for : 2 times.
VLC crashed for : 3 times.
VLC crashed for : 4 times.

However, I want my script to print the output like:

VLC crashed for : 0 times. then 1,2,3, and so on... I just want to replace the 0,1,2,3 but dont want to make new echo line.

Any idea? Thanks.

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: How to replace value in same line in DOS window.

#2 Post by foxidrive » 16 Apr 2013 04:14

A common way to display that is to use CLS before echoing.

The other way is to use backspaces, and is more convoluted.

level3
Posts: 4
Joined: 16 Apr 2013 03:47

Re: How to replace value in same line in DOS window.

#3 Post by level3 » 16 Apr 2013 04:21

Thnx, any code hint?

Now I'm doing "echo VLC Crashed for %count% times.

What to replace here?

level3
Posts: 4
Joined: 16 Apr 2013 03:47

Re: How to replace value in same line in DOS window.

#4 Post by level3 » 16 Apr 2013 04:34

Never mind, got it working with CLS.

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: How to replace value in same line in DOS window.

#5 Post by !k » 16 Apr 2013 07:07

Code: Select all

@echo off
setlocal enabledelayedexpansion

(echo.N cr.txt&echo.e 100 0d 0d&echo.r cx&echo.02&echo.w 100&echo.q)|debug>NUL
:: Assign a single CR to a variable, use a textfile with 2 bytes of 0x0d, 0x0d
for /f "tokens=1" %%x in ('type cr.txt') do set "CR=%%x"

::Simple sample, count from 1 to 2000, print it on the same line
for /L %%c in ( 1,1,20000) do (
   <nul set /p ".=Count: %%c!CR!"
)
echo.

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: How to replace value in same line in DOS window.

#6 Post by foxidrive » 16 Apr 2013 07:19

A method to get a CR without debug, as debug is not supported on 64 bit Windows.

for /f %%A in ('copy /Z "%~dpf0" nul') do set "CR=%%A"

level3
Posts: 4
Joined: 16 Apr 2013 03:47

Re: How to replace value in same line in DOS window.

#7 Post by level3 » 16 Apr 2013 08:17

wow... thanks !k this is exactly what i was looking for.

thank you all for sharing insights.

Post Reply