Page 1 of 1

Append command line output dynamically

Posted: 13 Dec 2011 09:10
by tiggyboo
Sorry for the surreal subject, but I wasn't sure how to describe this in a one liner. What I'd like to be able to do is basically avoid generating a newline in my output, something like this:

echo "Processing xyz..."
[script does some stuff]

Then actually append something like an "ok" at the end of the existing output line so it ultimately looks like this when it's processing is done:

Code: Select all

Processing xyz... ok

As opposed to a newline being generated like this:

Code: Select all

Processing xyz...
ok


I don't want to just build the whole string and then display it when the processing is done because I want to have visual feedback on when the processing has started, how long it's taking for each item, which item it might hang on, etc.

Any suggestions appreciated - hope this was a clear as mud!

Re: Append command line output dynamically

Posted: 13 Dec 2011 09:26
by orange_batch
Here's a brief example of an echo system I developed. It's actually a simple concept.

Code: Select all

@echo off&setlocal enabledelayedexpansion

call :echo "Hello"
call :echo "World"
call :echo "I"
call :echo "Like"
call :echo "Bananas"
pause

set /a #echolen-=1
call :echo /r

call :echo "Oranges"
pause

set /a #echolen-=2
call :echo /r

call :echo "Love"
call :echo "Orange Batch"
pause

pause
exit

:echo
if "%~1" NEQ "/r" (
set "#echo=%~1"
echo(!#echo!
set /a #echolen+=1
set "#echo!#echolen!=%~1"
) else (
cls
for /l %%x in (1,1,%#echolen%) do (
echo(!#echo%%x!
))
exit/b

Do all your echos using call :echo " text here "
Set number of lines to go back using set /a #echolen-=number
Refresh the window using call :echo /r

Re: Append command line output dynamically

Posted: 13 Dec 2011 09:35
by dbenham
There are multiple threads with this answer, but I can't seem to find them quickly.

SET /P is able to print info to the screen without issuing a new line. Redirecting input to nul causes it to finish without waiting for input. The variable that gets assigned does not matter. Since it receives no input, the value will not change.

Code: Select all

<nul set /p junk=Processing xyz...
rem Some arbitrary process
echo ok


Dave Benham

Re: Append command line output dynamically

Posted: 13 Dec 2011 14:43
by tiggyboo
Thanks, just what I was looking for. I had problems finding this issue referenced before (what do you search for?) as well... but I apologize for the apparent repeat.