Append command line output dynamically

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tiggyboo
Posts: 5
Joined: 28 Oct 2011 15:06

Append command line output dynamically

#1 Post by tiggyboo » 13 Dec 2011 09:10

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!

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: Append command line output dynamically

#2 Post by orange_batch » 13 Dec 2011 09:26

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

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Append command line output dynamically

#3 Post by dbenham » 13 Dec 2011 09:35

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

tiggyboo
Posts: 5
Joined: 28 Oct 2011 15:06

Re: Append command line output dynamically

#4 Post by tiggyboo » 13 Dec 2011 14:43

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.

Post Reply