batch file - Windows cmd: echo without new line but with CR -
i write on same line inside loop in windows batch file. example:
setlocal enabledelayedexpansion set file_number=0 %%f in (*) ( set /a file_number+=1 echo working on file number !file_number! something.exe %%f ) setlocal disabledelayedexpansion
this result in:
echo working on file number 1
echo working on file number 2
echo working on file number 3
. . .
i of them on same line. found hack remove new line (e.g. here: windows batch: echo without new line), produce 1 long line.
thanks!
@echo off setlocal enableextensions enabledelayedexpansion /f %%a in ('copy "%~f0" nul /z') set "cr=%%a" set "count=0" %%a in (*) ( set /a "count+=1" <nul set /p ".=working on file !count! !cr!" )
the first for
command executes copy operation leaves carriage return character inside variable.
now, in file loop, each line echoed using <nul set /p
output prompt string without line feed , without waiting input (we reading nul
). inside data echoed, include carriage return obtained.
but work, cr
variable needs echoed delayed expansion. otherwise not work.
if reason need disable delayed expansion, can done without cr variable using for
command replaceable parameter
@echo off setlocal enableextensions disabledelayedexpansion /f %%a in ('copy "%~f0" nul /z') ( /l %%b in (0 1 1000) ( <nul set /p ".=this line %%b%%a" ) )
Comments
Post a Comment