1.

Solve : Batch - ECHOJ Help?

Answer»

How can to cursor be sent to the echoj line beginning so that the next echoj will overwrite the text? Similar to pressing the {Home} key ... but executed by the batch file.I'm not a big fan of hybrid batch files, but I'm not sure your request can be DONE in pure batch. This little script uses JScript to create a carriage return character which can then be used within the batch code as needed. I find JScript preferable to VBScript by not using an intermediate WORK file. On the downside, JScript is case-sensitive and requires punctuation.

Code: [Select]@set @JScript=1/*
@echo off
::
:: Batch Code Goes here
::
setlocal EnableDelayedExpansion

For /F "delims=" %%a in ('cscript //nologo /E:JScript "%~dpnx0"') Do Set "CR=%%a"

for /L %%i in (1,1,20) do (
<nul set /p "=!date! !time! !CR!"
ping -n 2 127.0.0.1 > nul
)

goto :eof
*/

//
// JScript Goes Here
//
WScript.Echo (String.fromCharCode(13));

This is set up as a demo. After the JScript code runs, the CR variable contains a carriage return (no line feed). The second for STATEMENT outputs a timestamp overwriting the previous time stamp. JScript, unlike VBScript, supports block comments which is the key here. When the JScript engine runs, the batch code is invisible and when the batch code runs, the JScript code is invisible.

You can replace the second for statement with any batch language you need. The rest of the code is critical for this to work, especially the FIRST line and the paired end of JScript comment line (*/).

Good luck.

PS. EchoJ and chgColor was a topic of discussion earlier.this year. You might want to check it out.



Discussion

No Comment Found