Generate nearly any character, including TAB, from batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Squashman
Expert
Posts: 4111
Joined: 23 Dec 2011 13:59

Re: Generate nearly any character, including TAB, from batch

#16 Post by Squashman » 12 Oct 2017 07:58

Noticed something interesting today with using hex 07. I could only output multiple beeps if I had extra code below that was still executing or just use the timeout or pause commands. Did not matter that I was using FOR /L or a regular FOR. I wouldn't think you could break out of the FOR /L like that.

Code: Select all

@echo off
setlocal

::Define a Linefeed variable
set LF=^


::above 2 blank lines are critical - do not remove.

call :hexprint "0x07" rtnvar

REM FOR /L %%L IN (1,1,5) do echo %rtnvar%
FOR %%L IN (1 2 3 4 5) do echo %rtnvar%
REM pause
timeout /t 5 >nul
exit /b

:hexPrint  string  [rtnVar]
  for /f eol^=^%LF%%LF%^ delims^= %%A in (
    'forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(%~1"'
  ) do if "%~2" neq "" (set %~2=%%A) else echo(%%A
exit /b


EDIT: After further investigation, the FOR /L is actually executing all interations, it is just the echo of the BELL command does not echo out all iterations before the script closes.

Post Reply