Echoing in the same line Echoing in the same line windows windows

Echoing in the same line


I suppose you are using dos/nt-batch.

It is possible with the set /p command, because set /p doesn't print a CrLf

set /p "=Executing backup...." <nulecho OK

Also it's possible to erase the line with a CR character.It's important to know that whitespace characters at the front of an set /p are ignored (in Vista, not in XP), so the !cr! has to placed later or at the end.A CR can only be displayed with delayedExpansion, because %cr% works, but CR characters are removed in the percent expansion phase(or directly after this phase), but not in the delayed expansion phase.

Example of a counter which use only one line for displaying

@echo offsetlocal EnableDelayedExpansion EnableExtensionscall :CreateCRfor /l %%n in (1,1,10000) do (    set /P "=Count %%n!CR!" <nul)echo(goto :eof:CreateCRrem setlocal EnableDelayedExpansion EnableExtensionsset "X=."for /L %%c in (1,1,13) DO set X=!X:~0,4094!!X:~0,4094!echo !X!  > %temp%\cr.tmpecho\>> %temp%\cr.tmpfor /f "tokens=2 usebackq" %%a in ("%temp%\cr.tmp") do (   endlocal   set cr=%%a   goto :eof)goto :eof

EDIT: Explanation, how the variable cr is created (Done with a trick)

After setting variable X to a single dot (the character itself is unimportant), it is repeated to become 8188 characters by way of for /L %%c in (1,1,13) DO set X=!X:~0,4094!!X:~0,4094!

Then the variable, two spaces and both a CR and LF are echoed into a file with echo !X! > %temp%\cr.tmp (Notice the two spaces between the !X! and the > and the natural line endings echo amends internally)

We now have 8192 characters, but the data buffer can only hold 8191 characters, so the last character (the linefeed) will be dropped!

In the next line echo\>> %temp%\cr.tmp, another CR/LF set is appended to the file (the \ in the command is just to output nothing bar the carriage return and line feed, as echo by it's self will output ECHO is ON/OFF), that's important, as a single CR can't be read at the end of a line (More later).

So the file now contains <8188 .'s><SPACE><SPACE><CR><CR><LF>

The for /f "tokens=2 usebackq" %%a in ("%temp%\cr.tmp") do reads the second token, the delimters are standard space and tab, so the second token is only a single CR, as the following CR/LF is removed as standard line ending.

Finally the endlocal is used to return to an environment without the temporary variables X, c and a existing (As with the endlocal in brackets, it allows the setting of cr before the endlocal actually takes affect at the end of the brackets (could also be written as for /f "tokens=2 usebackq" %%a in ("%temp%\cr.tmp") do endlocal&set cr=%%a&goto :eof)

Additionally

This was my first way to create a CR character, but it needs some time and a temporary file.
Later I saw a simpler method of retrieving the CR from a copy /z command.

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


Try this on Posix system (Linux)

echo -n "Executing backup.... "echo -n "backup procedure "echo "Ok"

It is much harder on Windows. You will need to use something like this:

@echo offecho|set /p ="Executing backup...."echo|set /p =" backup procedure"

Check this post: http://www.pcreview.co.uk/forums/showpost.php?s=1a20b16775d915998b30bd76a0ec5d35&p=4432915&postcount=7.


It's a bit of a hack, but here is an article describing how to do it for Windows.

From the article, the final result (edited for your setup) looks like this:

SET /P var=Backing up%Result%....<NULBackup_process %Result% >NUL 2>&1IF ERRORLEVEL 1   ECHO FAIL ELSE  ECHO OK