0

I made a simple little program in batch that types out character by character the contents of the "_text" variable:

@echo off
SET _start=-1
SET _length=1
SET _text=This is an automated typing machine.

:loop
SET /a "_start=_start+1"
CALL SET _substring=%%_text:~%_start%,1%%
<nul set /p =%_substring%
ping -n 1 -w 1.1.1.1 > nul
goto :loop

However, if you run the program, you can see that any spaces in the "_text" variable was skipped. How can I fix this?

Human.bat
  • 145
  • 1
  • 14
  • SET /P is stripping the leading space. This question has been asked and answered in the past on SO. I will give you a hint on how to solve this. Use the PROMPT command and capture a backspace to a variable. – Squashman Jan 29 '16 at 23:22

1 Answers1

2

You can do something like this:

@echo off
setlocal EnableDelayedExpansion
SET _start=-1
SET _length=1
SET "_text=This is an automated typing machine."

:loop
SET /a "_start=_start+1"
CALL SET "_substring=%%_text:~%_start%,1%%"
if "%_substring%"=="" goto end
<nul set /p "=.[bs]%_substring%"
ping -n 1 -w 1.1.1.1 > nul
goto :loop
:end
echo.
pause

However, instead of the [bs], you should put the backspace character, copied from this text-file, as discussed in this answer.

Community
  • 1
  • 1
Dennis van Gils
  • 3,487
  • 2
  • 14
  • 35